uniapp configuration chooseLocation WeChat applet Tencent map selection point
Scenes
Use the map point selection search function, echo function, and mobile point selection function in uniapp
The API used is uni.chooseLocation
to look at the properties in detail
-
latitude : Latitude of the destination, Number
-
longitude : the longitude of the destination, Number
-
keyword: search keyword, only App platform supports String
-
success: the callback function Function of the successful interface call
- success return parameter description
- name : location name
- address: detailed address
- latitude: latitude, floating point number
- longitude: longitude, floating point number
- success return parameter description
-
fail: the callback function Function of interface call failure
-
complete: the callback function Function for the end of the interface call
combat
HTML
<view class="icon-corlor" @click="pointer">选择地址</view>
JS: directly call the uni.chooseLocation API here
亿点小知识:chooseLocation 属于封装型API,开发者若觉得不够灵活,可自行基于原始的 map 组件进行封装。插件市场已经有各种封装样例了
pointer() {
uni.chooseLocation({
success: async function(res) {
console.log(res.address, "返回地址")
},
fail: function(e) {
console.log(e, "报错")
}
})
},
The above has achieved the basic use
Error requiredPrivateInfos field
The following error may be reported: wx.chooseLocation need to be declared in the requiredPrivateInfos field in
This is because it needs to be configured in requiredPrivateInfos:
For applets released after July 14, 2022, when using the following 8 geographic location-related interfaces, you need to declare this field, otherwise it will not work properly. Mini programs released before July 14, 2022 will not be affected.
In the WeChat applet it is app.json
a file but in uniapp manifest.json
we find the source code view
and configure the required plug-ins in the code
"mp-weixin" : {
"appid" : "wx6a2自己的id",
"requiredPrivateInfos": [
"getLocation",
"onLocationChange",
"startLocationUpdateBackground",
"chooseAddress",
"chooseLocation"
]
}
Another thing to note here is that you need to go to the WeChat public official platform to open permissions
In the applet management background, "Development" - "Development Management" - "Interface Settings" self-activate the interface permission
The above is the uniapp configuration chooseLocation WeChat applet Tencent map selection Thank you for reading.
If you encounter other problems, you can discuss and study with me in private.
If it is helpful to you, please 点赞
bookmark it. Thank you~!
Pay attention to favorite bloggers and will continue to update...