小程序获取用户当前经纬度


 

  //获取位置
  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)的坐标在计算距离的时候更为精确

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM