微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息


微信小程序获得经纬度

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