//获取位置 getSelfLocation: function (varSendOrgId) { var that = this;
//用户授权过可以直接获取位置 wx.getLocation({ //type: 'wgs84', type: 'gcj02', success: function (res) { var latitude = res.latitude; var longitude = res.longitude; that.setData({ selfLongitude: longitude,//经度 selfLatitude: latitude,//纬度 }); }, fail: function (res) { setTimeout(function () {
//需要用户授权获取位置 wx.getSetting({ success: (res) => { if (!res.authSetting['scope.userLocation']) { wx.openSetting({ success: (response) => { wx.showModal({ title: '请重新授权', content: '需要获取您的地址信息', success: function (data) { wx.getLocation({ success: function (res) { var latitude = res.latitude; var longitude = res.longitude; that.setData({ selfLongitude: longitude,//经度 selfLatitude: latitude,//纬度 }); } }) } }); } }) } } }) }, 1000); } }); },
经过测试,使用GCJ02(火星坐标)比WGS84(GPS)的坐标在计算距离的时候更为精确