微信小程序——获取具体地理位置信息

通过微信自己的接口API,用户授权后获取到经纬度,通过经纬度调用地图接口返回地理位置信息。

简单、明了!!!(网上自己查询的文档进行编程,转载请注明出处)

代码如下:

qqMapApi: 'http://apis.map.qq.com/ws/geocoder/v1/', //地图接口链接
 
//获取经纬度
getPosition() {
let that = this;
wx.getLocation({
type: 'wgs84',
success: function(res) {
var latitude = res.latitude;
var longitude = res.longitude;
// wx.setStorageSync('latitude', latitude) //纬度
// wx.setStorageSync('longitude', longitude) //经度
var qqMapApi = that.qqMapApi + "?location=" + latitude + ',' +
longitude + "&key=" + 'XVLBZ-BSU66-ULJSQ-MFGXD-TM7GZ-55F2M' + "&get_poi=1";
wx.request({
url: qqMapApi,
data: {},
method: 'GET',
success: (res) => {
console.log(res)
if (res.statusCode == 200 && res.data.status == 0) {
that.country = res.data.result.address_component.nation;
that.province = res.data.result.address_component.province;
that.city = res.data.result.address_component.city;
that.county = res.data.result.address_component.district;
that.street = res.data.result.address_component.street;
}
}
})
},
fail() {
that.fn_fail();
}
})

},
原文地址:https://www.cnblogs.com/zhangjiabin/p/8276400.html