iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >uni-app微信小程序结合腾讯地图获取定位导航以及城市选择器
  • 740
分享到

uni-app微信小程序结合腾讯地图获取定位导航以及城市选择器

uni-app小程序 2023-09-10 12:09:17 740人浏览 薄情痞子
摘要

目录 第一步:登录小程序公众平台==>设置==>第三方设置  第二步:登录腾讯地图申请属于自己小程序的key  第三步:找到腾讯地图的插件​​​​​​​  第四步:添加插件与允许授权  第五步:使用 第一步:登录小程序公众平台==>

目录

第一步:登录小程序公众平台==>设置==>第三方设置

 第二步:登录腾讯地图申请属于自己小程序的key

 第三步:找到腾讯地图的插件​​​​​​​

 第四步:添加插件与允许授权

 第五步:使用


第一步:登录小程序公众平台==>设置==>第三方设置

 

 第二步:登录腾讯地图申请属于自己小程序的key

 腾讯地图后台: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

--结束END--

本文标题: uni-app微信小程序结合腾讯地图获取定位导航以及城市选择器

本文链接: https://www.lsjlt.com/news/402297.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作