开发者工具获取位置错误
发布于 5 年前 作者 yong81 11602 次浏览 来自 问答

获取的位置一直是北京,但是我不在北京,而且昨天还能正常获取

3 回复

开发者工具获取到的应该是你IP所在地址吧

真机正常吗?

get_my_point: function () {

wx.getLocation({

type: ‘gcj02’,

success: function (res) {

console.log(res);

wx.setStorageSync(‘my_point’, res);

//var latitude = res.latitude

//var longitude = res.longitude

//var speed = res.speed

//var accuracy = res.accuracy

}

})

},

get_quanxian:function()

{ var that=this;

wx.getSetting({

success: (res) => {

// res.authSetting[‘scope.userLocation’] == undefined    表示 初始化进入该页面

// res.authSetting[‘scope.userLocation’] == false    表示 非初始化进入该页面,且未授权

// res.authSetting[‘scope.userLocation’] == true    表示 地理位置授权

//console.log(“oooo” + res.authSetting[‘scope.userLocation’]);

if (res.authSetting[‘scope.userLocation’] != undefined && res.authSetting[‘scope.userLocation’] != true) {

//未授权

wx.showModal({

title: ‘请求授权当前位置’,

content: ‘需要获取您的地理位置,请确认授权’,

success: function (res) {

if (res.cancel) {

//取消授权

wx.showToast({

title: ‘拒绝授权’,

icon: ‘none’,

duration: 1000

})

} else if (res.confirm) {

//确定授权,通过wx.openSetting发起授权请求

wx.openSetting({

success: function (res) {

if (res.authSetting[“scope.userLocation”] == true) {

wx.showToast({

title: ‘授权成功’,

icon: ‘success’,

duration: 1000

})

//再次授权,调用wx.getLocation的API

that.get_my_point();

} else {

wx.showToast({

title: ‘授权失败’,

icon: ‘none’,

duration: 1000

})

}

}

})

}

}

})

}

else

{

console.log(“111”);

that.get_my_point();

}

}

})

}

回到顶部