This article brings you an example of WeChat applet: how to call Tencent Map to obtain jsonp data. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Use the built-in js of the WeChat applet to call the Tencent map api to obtain the location information, and the returned jsonp data
The analysis method is as follows:
//根据经纬度对象获取位置详细信息 getLocationInfo: function (location){ let _this = this; var data = { location: location.latitude + "," + location.longitude, /*腾讯地图key*/ key: "************************", get_poi: 0 }; var url = 'https://apis.map.qq.com/ws/geocoder/v1/?'; wx.request({ type: "get", dataType: 'jsonp', data: data, jsonp: "callback", jsonpCallback: "QQmap", url: url, success: function(res) { let data = res.data; #此处data是格式化的字符串,并不是对象 var json = JSON.parse(data); #把data转换成对象 if (json.status == 0) { #此处写业务逻辑 } }, fail: function(res) { console.log(res) }, }) }
Related recommendations:
How to call API in WeChat applet to implement data request
How to pass parameters and receive data in WeChat applet
The above is the detailed content of WeChat Mini Program Example: How to call Tencent Map to obtain jsonp data. For more information, please follow other related articles on the PHP Chinese website!