微信小程序定位不准怎么解决?
最近有用户表示微信小程序定位不准,主要是体现在,开发了小程序获取经纬度的定位功能,但是最终发现小程序定位的结果和实际相差了1公里。小编经过搜索资料之后找到了解决办法,一起来看看吧。
在这里我们可以找到”当前位置经纬度“
getLocation: function ()
{
var that = this wx.getLocation(
{
success: function (res) {
console.log(res)
that.setData({
hasLocation: true,
location: formatLocation(res.longitude, res.latitude)//这里是获取经纬度
})
}
})
},
//将经纬度转换成城市名和街道地址:
onLoad: function (options) {
console.log('onLoad')
var that = this;
wx.getLocation({
success: function (res) {
wx.request({
url: 'api.map.baidu/geocoder/v2/?ak=btsVVWf0TM1zUBEbzFz6QqWF&callback=renderReverse&location='
+ res.latitude + ',' + res.longitude + '&output=json&pois=1', data: { },
header: { 'Content-Type': 'application/json' },
success: function(ops) {
console.log(ops.data)
}
})
// console.log(res)
// that.setData({
// hasLocation: true,
// location: formatLocation(res.longitude, res.latitude)
// })
}
})
}
这里用到微信小程序开发文档里面有发起的是s请求
参照文中的代码重新开发一次,就会出现如上图所示的小程序页面,只要这个页面出现,微信小程序定位不准的问题就代表已经圆满解决了,大家都学会了吗?更多相关资料请关注微信小程序商店。
微信小程序定位到input操作实例
微信小程序定位授权怎么弄
怎样才能实现微信小程序定位城市?
上一篇:微信小程序关键词配置怎么操作?
下一篇:微信公众号开发报价是怎样的?
