关于计算2点之间的距离都依赖了腾讯地图,所以请先在
下面具体讲计算2点之间距离的方法。
方法一:
getPosition: function() {var that = this;
wx.getLocation({
success:function(res) {
that.setData({
fromLng: res.longitude,
fromLat: res.latitude
})
}
})
},
2.通过腾讯地图 逆解析 你的目的地地址,获取经度,纬度:
wx.request({
url:'https://apis.map.qq.com/ws/geocoder/v1/',
data: {"key": "你的腾讯地图 key","address": "目的地"},
method:'GET',
success:function(res) {if(res.data.result) {
const addressLocation=res.data.result.location;
const courseLat= addressLocation.lat;//获取目的地的纬度
const courseLng = addressLocation.lng;//获取目的地的经度
}
that.setData({