微信小程序自動定位,通過百度地圖根據經緯度獲取該地點所在城市信息


微信小程序獲得經緯度

var that = this
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        console.log(res)
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude
        })
    }
})

百度地圖api

'https://api.map.baidu.com/geocoder/v2/?location=' + res.latitude+',' + res.longitude+'&output=json&pois=1&ak='+ baiduAK{注冊百度地圖api獲得的accessKey}  http://lbsyun.baidu.com/
 
返回json里的city字段就是城市信息了。

 


免責聲明!

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



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