微信小程序调用腾讯地图选点
業務:
小程序中實現選擇地址
解決方案:
1.在小程序后臺的設置>第三方設置>在插件管理中添加插件搜索>騰訊位置服務地圖選點
2.插件引入后可以點擊詳情查看文檔
(1)首先在app.json中添加插件
//app.json
"plugins":{
?? ??? ??? ?"chooseLocation":{
?? ??? ??? ??? ?"version":"1.0.9",
?? ??? ??? ??? ?"provider":"wx76a9a06e5b4e693e"//按照文檔的原樣復制,非自己小程序的appId
?? ??? ??? ?}
?? ??? ?},
(2)
//app.json
{
? "permission": {
? ? "scope.userLocation": {
? ? ? "desc": "你的位置信息將用于小程序定位"
? ? }
? }
}
在uniapp中開發可以放在manifest.json的源碼視圖編寫:
"mp-weixin" : {
????????"plugins":{
?? ??? ??? ?"chooseLocation":{
?? ??? ??? ??? ?"version":"1.0.9",
?? ??? ??? ??? ?"provider":"wx76a9a06e5b4e693e"
?? ??? ??? ?}
?? ??? ?},
????????"permission" : {
? ? ? ? ? ? "scope.userLocation" : {
? ? ? ? ? ? ? ? "desc" : "你的位置信息將用于小程序位置接口的效果展示"
? ? ? ? ? ? }
? ? ? ? },
}
3.在頁面中使用
<script>const chooseLocation = requirePlugin('chooseLocation');export default {data(){return{latitude:'',longitude:''}}, onShow(){const resAddress=chooseLocation.getLocation();//地圖選點后返回當前頁面通過這種方式將內容取出if(resAddress){this.jobCity= resAddress.name; this.findPostBasicInfoVos({lat:resAddress.latitude,lng:resAddress.longitude}); } },onHide(){//有些業務場景當離開頁面后將原本存在插件中位置信息清空chooseLocation.setLocation(null);},methods:{showMap(){ const key = ''; //使用在騰訊位置服務申請的key,申請地址https://lbs.qq.com/const referer = '小程序的名稱'; //調用插件的app的名稱const location = JSON.stringify({latitude: this.latitude,longitude: this.longitude});const category = '生活服務'; wx.navigateTo({url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`});}}} </script>?注意
1.如果報t is not function
使用小程序插件報錯t is not function_路光.的博客-CSDN博客
2.還需要在app.json中配置
"requiredPrivateInfos":["getLocation","chooseLocation" ]總結
以上是生活随笔為你收集整理的微信小程序调用腾讯地图选点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cam350菜单怎么切换成中文_电子设计
- 下一篇: 2010年9月_软件学报_基于树的数据收