如何才能从Mapbox导航路线得到距离?在双格式下,我不想画路线--我只需要计算两点之间的距离,我已经能够用Truf计算出距离
Storelocation = Point.fromLngLat(Stores.latitude, Stores.longitude)
Userlocation = Point.fromLngLat(UserLocation.Latitude, UserLocation.Longitude)
Distance = TurfMeasurement.distance(Storelocation, Userlocation, TurfConstants.UNIT_KILOMETERS)
但问题是,用这种方法不计算路线内的距离,它只是计算直线从点到点的 ,例如 在Google地图上的距离是9公里,但是用这种方法上面的距离是6公里。
private fun getRout(){
NavigationRoute.builder(this)
.accessToken(Mapbox.getAccessToken()!!)
.origin(Userlocation)
.destination(Storelocation).build().getRoute(object :Callback<DirectionsResponse> {
override fun onResponse(call: Call<DirectionsResponse>, response: Response<DirectionsResponse>) {
val rout = response ?: return
val body = rout.body() ?: return
if (body.routes().count() == 0 ){
return
navigationMapRoute = NavigationMapRoute(null, mapView, map)
// Get Distance
Distance = ??
override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {