uniapp configuration chooseLocation WeChat applet Tencent map selection point

uniapp configuration chooseLocation WeChat applet Tencent map selection point

insert image description here

Scenes


Use the map point selection search function, echo function, and mobile point selection function in uniapp

The API used is uni.chooseLocationto 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
  • 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

insert image description here
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.jsona file but in uniapp manifest.jsonwe find the source code view
insert image description here
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

insert image description here
insert image description here

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...

Guess you like

Origin blog.csdn.net/qq2754289818/article/details/131457135