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) } }) } })