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;
};
//经度转换
transformLongitude(x, y) {
let num = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
num += (20.0 * Math.sin(