android\ios壳嵌入h5调取原生功能获取当前的地理位置
wgs84 返回 gps 坐标,gcj02 返回国测局坐标。
gcj02参数获取的地址有偏差,而用定位 wgs84参数则不返回地址,所以需要将wgs84坐标转gcj02坐标,然后再调用高德地图接口获取地址。
方法一:
1.GPS转高德坐标
class Gps {
//构造函数
constructor(obj = {}) {
let { longitude, latitude } = obj;
if (longitude === undefined || latitude === undefined) {
return console.error("经纬度参数不能为空!");
}
this.PI = 3.14159265358979324;
return this.getCoordinate(longitude, latitude);
};
//纬度转换
transformLatitude(x, y) {
let num = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
num += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
num += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
num += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
return num;

文章介绍了如何在Android和iOS的H5环境中调用原生定位功能获取坐标,并处理WGS84与GCJ02坐标系之间的转换。通过提供的转换函数,可以将GPS的WGS84坐标转换为适用于中国的GCJ02坐标,进而使用高德地图接口获取精确地址。此外,文章还提到了高德地图的官方坐标转换和地理编码API的使用方法。
最低0.47元/天 解锁文章
174





