'mapbox-gl-js route is not accurate

route image

I'm new with map box and java scripts, i have try route mapping system but its not accurate. i don't know if routing map using map box-gl-js is normally its become like this or my code cause that problem. i follow the tutorial from https://docs.mapbox.com/help/tutorials/getting-started-directions-api/ .



Solution 1:[1]

I had the same problem and I found the answer in another Stackoverflow question (Does Mapbox Directions API limit the number or precision of coordinates in a response?):

You can use the overview=full which is an optional parameter in your queries to get the most detailed geometry, so your queries would look something like this:

Query 1

https://api.mapbox.com/directions/v5/mapbox/driving/-73.989%2C40.733%3B-74%2C40.733.json?access_token=my_access_token&geometries=geojson&overview=full

Query 2

https://api.mapbox.com/directions/v5/mapbox/driving/-73.989%2C40.733%3B-94%2C40.733.json?access_token=my_access_token&geometries=geojson&overview=full

If you put them in the API playground, you should see a more detailed route for your 2nd Query.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1