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