在uniapp中app端,uni.getLocation获取经纬度会有大概1-2公里的偏差,在实际项目中,有的需求对经纬度的准确度要求比较严格,研究了很多种方式,最终发现使用高德地图api的微信小程序的插件获取的准确性是最准的,偏差最小的。
1.先去高德地图获取key,注意,这里是要获取微信小程序类型的key

2.然后回到首页开发支持-微信小程序插件中下载sdk(amap-wx.js )
 
3.在项目中引入:按你自己的目录填写
import amap from "@/js_sdk/js-amap/amap-wx.130.js"
4.初始化
data中定义 amapPluginInstance:null,
methods中:
initMap() {
                 this.amapPluginInstance = new amap.AMapWX({
                     key: 'a4cea069ff4d5df405d20b2f653fb5f4' //该key 是在高德中申请的微信小程序key
                 });
                 this.getCurrentPos()
 },
getCurrentPos() {
                 let _self = this;
                 this.amapPluginInstance.getRegeo({
                     success: (res) => {
                         console.log(res); //可自己查看所需返回值取用
                         _self.address = res[0].regeocodeData.formatted_address;
                         _self.lat = res[0].latitude; //纬度
                         _self.lng = res[0].longitude; //经度
                         console.log("高德地图坐标经纬度:[" + _self.lat + "," + _self.lng + "]");
                     },
                     fail: (data) => {
                         console.log(data)
                     }
                 })
             },





![2023-07-11:给定正整数 n, 返回在 [1, n] 范围内具有 至少 1 位 重复数字的正整数的个数。 输入:n = 100。 输出:10。](https://img-blog.csdnimg.cn/279e9b2bee2a4958a6693300bd86200f.png)













