WeChat Mini Program Example: How to call Tencent Map to obtain jsonp data

不言
Release: 2018-08-10 17:07:56
Original
6089 people have browsed it

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)
      },
    })
  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template