在微信小程序中将获取到的经纬度(经度纬度)转地址(地名)

var QQMapWX = require('qqmap-wx-jssdk')
var qqmapsdk = new QQMapWX({
    key: '填写你的key' // 必填
})
    wx.getLocation({
      type: 'wgs84',
      success (res) {
          console.log('纬度', res.latitude, '经度', res.longitude)
          wx.setStorageSync('latitude', res.latitude)
          wx.setStorageSync('longitude', res.longitude)
      },
     //wx.getLocation  回调里面把上面获取到的经纬度给引入的qqmap-wx-jssdk就可以获取到对应的地点了
      complete () {
        // 坐标转换
        qqmapsdk.reverseGeocoder({
          // 位置坐标,默认获取当前位置,非必须参数
            location: {
              latitude: wx.getStorageSync('latitude'),
              longitude: wx.getStorageSync('longitude')
            },
            success: function (res) {
              console.log(res.result.address_component.city)
              wx.setStorageSync('address_component', res.result.address_component.city)
            },
          fail: function (error) {
            console.error('错误', error)
          }
        })
      }
    })

 微信公众平台 | 小程序 >   开发  在这里配置域名  https://apis.map.qq.com 

posted @ 2019-01-25 10:59  Model-Zachary  阅读(1559)  评论(0编辑  收藏  举报