- 申請開發者密鑰(key):申請密鑰
-
開通webserviceAPI服務:控制台 ->key管理 -> 設定(使用該功能的key)-> 勾選webserviceAPI -> 儲存
(小程式SDK需要用到webserviceAPI的部分服務,是以使用該功能的KEY需要具備相應的權限)
- 下載下傳微信小程式JavaScriptSDK,微信小程式JavaScriptSDK v1.2
- 安全域名設定,在“設定” -> “開發設定”中設定request合法域名,添加https://apis.map.qq.com
- 小程式示例
const QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
const wxMap = new QQMapWX({
key: '****-GP***-RB***-B**US-****-RZ**Y' // 必填
});
onShow () {
/**經緯度逆解析 */
this.reverseGeocoder()
},
/**經緯度逆解析 */
reverseGeocoder() {
const that = this;
wx.getLocation({
type: 'gcj02',
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
wxMap.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
success: function (res) {
const { city } = res.result.address_component
console.log(city);
that.setData({
city,
})
},
});
},
fail(res) {
console.log(res)
}
})
},
2. 使用方法
文檔位址http://lbs.qq.com/qqmap_wx_jssdk/index.html
使用方法
微信小程式-經緯度逆解析詳細位址
https://lbs.qq.com/service/webService/webServiceGuide/webServiceOverview