The WeChat Mini Program uses markers in the map to display the distance error after obtaining the user's location

The error is because the default of the applet is that wgs84 is
changed to gcj02 and the error will be reduced a lot
more intuitively.
Below are the coordinates of gcj02. Below the map center point and the markers
Insert picture description here
are the coordinates of wgs84.
Pai Daxing is the markers of the user's latitude and longitude marks obtained by the wgs84 coordinates.
Kumamoto bears the latitude and longitude obtained by gcj02 before. The
Insert picture description here
error is still very large.
Looking at these three articles, you should be able to understand that the
latitude and longitude deviation correction of network maps such as Baidu and Google Gaode and related coordinate system problems
are used in the WeChat applet. Map and positioning Some pits and experiences
WeChat applet-Tencent map shows the deviation problem.
There is also a website that can help us get the latitude and longitude and convert the coordinates.

There is also a website that can help us get the latitude and longitude and convert the coordinates.
Here is a simple code

  wx.getLocation({
      type: 'gcj02',
  onLoad: function (options) {
    var that=this;
    wx.getLocation({
      type: 'gcj02',

      success: function (res) {
        console.log(res);
        var latitude = res.latitude;
        //getApp().globalData.latitude = res.latitude;
        var longitude = res.longitude;
        that.setData({
          latitude: latitude,
          longitude: longitude,//buyong在上面的data中初始化变量,在这set
          
          markers: [{
            iconPath: "/image/fe6e546034a85edfa278dd3546540923dc54758a.jpg",
            id: 0,
            latitude: latitude,
            longitude: longitude,
            width: 50,

            height: 50
          }],
            hou:true
        })
        //console.log(latitude);
        //弹框

      }
    })
  },

Guess you like

Origin blog.csdn.net/weixin_40938312/article/details/104186293