// 想要通过api获取用户位置,但是目前定位不精准,只能获取当地市政府的位置。
wx.getLocation({
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
isHighAccuracy: true, // 启用高精度
highAccuracyExpireTime: 8000, // 超时时间≥3000ms
success: function (res) {
let latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
let longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
console.log("定位结果:"+latitude+","+longitude);
alert('定位结果:'+latitude+','+longitude);
localStorage.setItem('gps', latitude + ',' + longitude);
we.geocoderGps(latitude + ',' + longitude).then(geo => {
console.log(geo);
alert('返回地图定位结果:'+geo);
if (geo.data.code === 200) {
localStorage.setItem('address', geo.data.data);
}
})
}
})
参考公众号JS-SDK文档。
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
可以,参考指引:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
wx.getLocation({ type:'wgs84',//默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj82success:function(res)f var latitude=res.latitude;//纬度,浮点数,范围为90~-90var longitude=res.longitude;//经度,浮点数,范围为180~-180。 var speed=res.speed;//速度,以米/每秒计 var accuracy=res.accuracy;//位置精度 });
微信公众号是单独的,可能名字一样,用法不一样
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#38
感谢