小程序获取地理位置偏差几百公里
发布于 5 年前 作者 qianglu 12364 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

这几天公司测试加油,开车全国跑,两天1000公里了结果不在北京了getLocation返回的还是北京的地理位置 用的也是gcj02

  • 预期表现

偏差在可控范围内

  • 复现路径

onShow(){

this.getStationList()

},

//获取油站

getStationList(){

let that = this;

let carList = app.globalData.carList || [];

let defaultCar = carList.find((item, index, arr) => { return item.flag == 1; }) || {};

let carId = defaultCar.carId || wx.getStorageSync(‘openId’);

let token = app.globalData.token;

try {

//if (that.data.staTionList.length) { return; }

wx.getLocation({

type: ‘gcj02’,

success: (res) => {

that.setData({

openTypeLocation: “”

})

let brandChannel = config.channel;

let token = app.globalData.token;

console.log(“getLocation:”, res)

wx.setStorageSync(‘userLocation’, res);

let pos = util.locationTranslate(res.longitude,res.latitude);

util.$request(

config.CircumStations,“GET”,{

latitude: pos.latitude,

longitude: pos.longitude,

radius: 50000,

carId,

brandChannel,

token

},

(res) => {

console.log(‘res-------’, res);

let staTionList = [];

let station = res.data.data[0];

if (station) {

staTionList.push(station)

}

that.setData({

staTionList

})

},

(err) => {

},

(res) => {

},

{

‘content-type’: ‘application/json’,

brandChannel: config.channel,

}

)

},

fail() {

that.setData({

openTypeLocation: “openSetting”

})

}

})

} catch (err) {

console.log(“ERR ______________”, err)

}

},

  • 提供一个最简复现 Demo
2 回复

4G还是wifi网络呢?

回到顶部