微信小程序中获取经纬度

index.wxml文件如下,longitude,latitude为以获取经纬度为地图中心,show-location为显示当前位置的绿色箭头

 
经度{{jd}}
纬度{{wd}}


index.js文件如下,wx.getLocation为获取用户位置API,首次需要用户授权,并打开gps,wgs84坐标系为gps坐标,gcj02为国测加密坐标,打开地图时使用。

onReady: function () {
    var that = this
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.setData({
          wd: latitude,
          jd: longitude
        })
      }
    })
  },



你可能感兴趣的:(小程序)