微信小程序——獲取具體地理位置信息


通過微信自己的接口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();
}
})

},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM