微信小程序获取位置信息wx.getLocation逆地址解析(坐标位置描述)
微信小程序代码onLoad: function (options) {var that = this;wx.getLocation({type: 'gcj02',success(res) {const lat = res.latitude;const lng = res.longitude;...
文章共212字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
微信小程序代码
onLoad: function (options) {
var that = this;
wx.getLocation({
type: 'gcj02',
success(res) {
const lat = res.latitude;
const lng = res.longitude;
// var x_PI= 3.14159265358979324 * 3000.0 / 180.0;
// var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
// var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
// var bd_lng = z * Math.cos(theta) + 0.0065;
// var bd_lat = z * Math.sin(theta) + 0.006;
var bd_lng = lng;
var bd_lat = lat;
that.setData({
lat: bd_lat,
lon: bd_lng
})
// console.log(that.data.lat+"lat");
// console.log(that.data.lon+"lon");
}
})
},
调用腾讯地址接口
https://lbs.qq.com/webservice_v1/guide-gcoder.html
https://apis.map.qq.com/ws/geocoder/v1/?location=
或者直接调用腾讯地图小程序接口进行转换
https://lbs.qq.com/qqmap_wx_jssdk/method-reverseGeocoder.html
更多推荐
已为社区贡献2条内容
所有评论(0)