Reputation: 101
I'm using Mapbox Matrix API for the first time. I'm trying to get the driving distance between two points:
Point A -105.044052,40.541783
Point B -105.43421,41.2337
My request is in this format:
https://api.mapbox.com/directions-matrix/v1/mapbox/driving/-105.044052,40.5417839;-105.434219,41.233714?sources=0&access_token=xyz
The response I'm getting is:
{"code":"Ok",
"durations":[[0.0,4687.2]],
"destinations":[
{
"distance":25.678536277,
"name":"Carlton Avenue",
"location":[-105.044287,40.541638]
},
{
"distance":199.410588356,
"name":"",
"location":[-105.436598,41.233736]
}
],
"sources":[
{
"distance":25.678536277,
"name":"Carlton Avenue",
"location":[-105.044287,40.541638]
}
]
}
My question is regarding distance results. The API says it returns all distances in meters. 199 meters is less than 1 mile. The two points should be around 80 miles apart. The duration of 4687 seconds sounds correct. That's 1.3 hours.
So why is the distance off?
Upvotes: 3
Views: 3385
Reputation: 4054
The odd-looking distances that are being returned are actually the distance the coordinates are from the end of the computed route. The southern point's coordinate is inside the building but the route starts 25.679m away outside on the road. Similarly, the northern point is almost 200m from the nearest part of the big road (I-80?) which is as close as Mapbox's routing system can calculate. GoogleEarth is able to run a route much closer.
The distance you want should be available by using some of the optional parameters in your API call and probably the Route Leg Object.
Upvotes: 2
Reputation: 2546
Is there a reason why you're using the Matrix API? If you'll always just need the distance between two lat/long coordinates, I'd encourage you to look into using the Mapbox Directions API.
See https://docs.mapbox.com/playground/directions as well.
Upvotes: 2