JS 11

  • we will start the Geocoding

  • and the directions API

The Mapbox Geocoding API allows us to forward geocoding and reverse geocoding:

Forward Geocoding is when we get the coordinates from a string:

forward Geocoded
chevron-rightMapbox Geocoding templatehashtag

The API returns a GeoJson feature array in Mapbox format:

The single feature being returned

We can filter the query with extra arguments:

In Reverse Geocoding we get strings locations from coordinates:

We get closest POI on coordinates
chevron-rightReverse Geocoding on map clickhashtag

The reverse geocoding query is the same as the forward, we change the query:

The Mapbox Geocoder plugin adds a search bar from which to search places:

chevron-rightMapboxGeocoder query parametershashtag

We can even add filters on the search results

We can use the geocoder events to check the search results:

chevron-rightUsing Layers on a Geocoder resulthashtag

We can use the GeolocateControl for the geolocation API to locate the user:

Mapbox Direction API

To use the Direction API mapbox gives us, we can use the SDK node.js client:

route object

We can draw it using expressions and click over waypoints:

we set the end waypoint on map click
chevron-rightUsing expressions to draw direction coordinateshashtag

We can directions for 2 clicked map points:

For the points on map click we:

Last updated