uniapp 获取当前经纬度及经纬度逆转

367 阅读1分钟

farmMap(){

const that = this;
uni.getLocation({
    type: 'gcj02', //返回可以用于uni.openLocation的经纬度
    success: function (res) {
                //经纬度逆转地址
                uni.request({
                  url: `${baseApi}/common/geocoder?location=${res.latitude},${res.longitude}&key=YHQBZ-LMYLF-VU5JS-JX7O6-D32Y5-GKFZD&get_poi=1`,
                  success: (res) => {
                    if (res.data.code == 0) {
                      res.data.msg = JSON.parse(res.data.msg);
                      console.log('经纬度逆编译成功', res);
                          that.keyword = res.data.msg.result.address?res.data.msg.result.address:''
                    }
                  },
                });

                console.log('获取当前经纬度',res)	
                that.latitude = res.latitude;
                that.longitude = res.longitude;

                //标记点
                that.covers=[{
                        id:1,
                        latitude:that.latitude,
                        longitude:that.longitude,
                }]
    }
});

},

image.png