微信小程序代码

  onLoad: function (options) {
    var that = this;
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        const lat = res.latitude;
        const lng = res.longitude;

        // var x_PI= 3.14159265358979324 * 3000.0 / 180.0;
        // var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
        // var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
        // var bd_lng = z * Math.cos(theta) + 0.0065;
        // var bd_lat = z * Math.sin(theta) + 0.006;
        var bd_lng = lng;
        var bd_lat = lat;

        that.setData({
          lat: bd_lat,
          lon: bd_lng
        })
        // console.log(that.data.lat+"lat");
        // console.log(that.data.lon+"lon");    
      }
    })
  },

调用腾讯地址接口

https://lbs.qq.com/webservice_v1/guide-gcoder.html

https://apis.map.qq.com/ws/geocoder/v1/?location= 

或者直接调用腾讯地图小程序接口进行转换

https://lbs.qq.com/qqmap_wx_jssdk/method-reverseGeocoder.html

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐