目录
第三步:找到腾讯地图的插件
第一步:登录小程序公众平台==>设置==>第三方设置
腾讯地图后台:https://lbs.qq.com/dev/console/application/mine
添加key,授权使用的小程序appId
插件文档:https://lbs.qq.com/miniProgram/plugin/pluginGuide/pluginOverview
"plugins" : { "chooseLocation" : { "version" : "1.0.9", "provider" : "wx76a9a06e5b4e693e" }, "citySelector" : { "version" : "1.0.1", "provider" : "wx63ffb7b7894e99ae" } },
地图中选择位置
const key = ""; //使用在腾讯位置服务申请的keyconst referer = ''; //调用插件的app的名称const location = JSON.stringify({// 修改时回显位置latitude: this.form.lat || this.location.latitude,longitude: this.form.lon || this.location.longitude});const category = '生活服务,娱乐休闲';uni.navigateTo({url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&location=' +location + '&category=' + category});
返回结果接收
const chooseLocation = requirePlugin('chooseLocation')onShow() {const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回nullconsole.log(location)if (location) {this.form.actiPlace = location.namethis.form.actiCity = location.citythis.form.lat = location.latitudethis.form.lon = location.longitude}},onUnload() {// 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果chooseLocation.setLocation(null);},
城市列表选择
const key = ''; //使用在腾讯位置服务申请的keyconst referer = ''; //调用插件的app的名称const hotCitys = ''; // 用户自定义的的热门城市uni.navigateTo({ url:`plugin://citySelector/indexkey=${key}&referer=${referer}&hotCitys=${hotCitys}`,})
返回结果接收
const citySelector = requirePlugin('citySelector')onShow() {const selectedCity = citySelector.getCity(); // 选择城市后返回城市信息对象,若未选择返回nullconsole.log(selectedCity)if (selectedCity) {let cityInfo = {city: selectedCity.fullname,latitude: selectedCity.location.latitude,longitude: selectedCity.location.longitude}},onUnload() {// 页面卸载时清空插件数据,防止再次进入页面,getCity返回的是上次的结果citySelector.clearCity();},
更多操作请参考腾讯文档:https://lbs.qq.com/miniProgram/plugin/pluginGuide/pluginOverview
来源地址:https://blog.csdn.net/weixin_46324536/article/details/128093042