腾讯位置服务地图选点,(相当于API文档页面)
https://mp.weixin.qq.com/wxopen/plugindevdoc?appid=wx76a9a06e5b4e693e
他的调用过程是,先打开一个page页面选择位置,然后回到之前的页面,触发onShow
,在 onShow 中获取刚刚选择的位置信息接入指引
https://lbs.qq.com/miniProgram/plugin/pluginGuide/locationPicker腾讯位置服务——key
https://lbs.qq.com/dev/console/application/mine
如上图,要勾选两处
- 需要在小程序后台,添加上插件
设置 > 第三方设置 > 插件管理
- 需要将插件配置到小程序中
{
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序定位"
}
},
"plugins": {
"chooseLocation": {
"version": "1.0.9",
"provider": "wx76a9a06e5b4e693e"
}
}
}
调用片段记录如下:
//这句提到最外层
const wxMiniPluginChooseLocation = requirePlugin('chooseLocation');
onUnload(){
// 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
wxMiniPluginChooseLocation.setLocation(null);
},
onShow(){
if (this.flagNavToPluginMap) {
this.flagNavToPluginMap = false;
const location = wxMiniPluginChooseLocation.getLocation();
console.log("location: ", location)
if (location) {
this.addInfo.province = location.province
this.addInfo.city = location.city
this.addInfo.area = location.district
//addrDetail,longitude,latitude,
this.addInfo.addrDetail = location.address
this.addInfo.longitude = location.longitude
this.addInfo.latitude = location.latitude
}
}
},
methods: {
//通过小程序插件获取地址信息
invokeWxMiniPluginGetLocation() {
const key = wxMiniPluginMapLocationKey
const referer = currentAppName
const location = JSON.stringify({
latitude: 39.89631551,
longitude: 116.323459711
});
const category = '生活服务,娱乐休闲';
this.flagNavToPluginMap = true;
wx.navigateTo({
// url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
// + '&location=' + location + '&category=' + category
url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
})
},
}
End