//需求是点击然后跳转地图可以导航到目标位置
直接调用uniApp自带的 uni.getLocation 再将主动或者后端返回的经纬度信息传入即可
这边因为后端传给我门店地址是百度地图 而uniApp需要的是腾讯地图经纬度 - 所以我进行了转换
goMapAddress() {
uni.getLocation()
//跳转导航页 并将参数携带
//#ifdef MP-WEIXIN
console.log('小程序App导航', this.addressInfo)
let that = this;
let latitude = Number(that.addressInfo.lat);
let longitude = Number(that.addressInfo.lng);
let TmapObj = this.$bMapTransQMap(latitude,longitude);
console.log(TmapObj,'obj')
uni.openLocation({
latitude:TmapObj.lat,
longitude:TmapObj.lng,
success: function() {
console.log('success');
}
});
//#endif
},
转换代码 - >
//百度地图经纬度转腾讯地图经纬度
Vue.prototype.$bMapTransQMap = function(lat,lng){
let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
let x = lng - 0.0065;
let y = lat - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
let lngs = z * Math.cos(theta);
let lats = z * Math.sin(theta);
return {
lng: lngs,
lat: lats
};
}
//需求是点击然后跳转地图可以导航到目标位置
直接调用uniApp自带的 uni.getLo