3***@qq.com
3***@qq.com
  • 发布:2024-06-28 19:34
  • 更新:2024-06-28 19:34
  • 阅读:41

UNIAPP结合高德API使用,经常出现和微信定位相差几公里得问题。请问是什么情况。

分类:uni-app

UNIAPP结合高德API使用,经常出现和微信定位相差几公里得问题。请问是什么情况。
高德的定位KEY+uniapp打出来的安卓包。别人村里定位时误差非常大。
图二是结合UNIAPP地图显示,在河左边,图一是微信定位,在河右上方了。
高精度也开了。

代码

uni.showLoading({
title: "loading",
mask: true,
});
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
highAccuracyExpireTime: 5000,
success: (data) => {
// const map = Coordinate.transformFromGCJToBaidu(data.latitude, data.longitude)
if (Coordinate.isLocationOutOfChina(data.latitude, data.longitude)) {
uni.showToast({
title: '定位获取失败!',
});
} else {
uni.request({
header: {
'Content-Type': 'application/text',
},
url: https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=${data.longitude},${data.latitude}&key=XXX,
success(res) {
console.log(res, "获取位置成功信息")
const address = res.data.regeocode;
//业务相关

              }).catch(res => {  
                uni.hideLoading();  
                uni.showToast({  
                  title: res.data,  
                  icon: "none",  
                  duration: 2000  
                });  
              });  
            },  
            fail: function(error) {  
              uni.hideLoading();  
              console.error(error);  
            }  
          })  
        }  
      },  
      fail(res) {  
        uni.showModal({  
          title: '定位获取失败,请检查权限!',  
          content: '具体原因:' + JSON.stringify(res),  
          showCancel: false  
        });  
        uni.hideLoading();  
      }  
    });
2024-06-28 19:34 负责人:无 分享
已邀请:
3***@qq.com

3***@qq.com (作者)

用的最新版本HBUILDER打包的

要回复问题请先登录注册