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

时间:2023-03-09 06:49:04
在微信小程序中将获取到的经纬度(经度纬度)转地址(地名)
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