小程序獲取用戶當前經緯度


 

  //獲取位置
  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