Skip to main content

Isochrone

This guide provides an overview of how to get time/distance isochrones using the Mapbox Java SDK.

The Mapbox Isochrone API computes areas that are reachable within a specified amount of time from a location and returns the reachable regions as contours of polygons and/or lines. If you're using this Java SDK wrapper with the Mapbox Maps SDK for Android, you can then display these areas or lines on a map.

For more information about this API, including its pricing structure, see the Mapbox Isochrone API documentation. Along with the API documentation, you can also view the Isochrone API example in the Mapbox Android demo app to see a complete example of how to use the API.

Criteria

Use the IsochroneCriteria class to conveniently reference a particular directions profile as you build the MapboxIsochrone.builder() object. Using the IsochroneCriteria class helps make sure that you pass correctly formatted parameters.

  • Driving: For automotive routing. This profile shows the fastest routes by preferring high-speed roads like highways.
  • Walking: For pedestrian and hiking routing. This profile shows the shortest path by using sidewalks and trails.
  • Cycling: For bicycle routing. This profile shows routes that are short and safer for cyclists by avoiding highways and preferring streets with bike lanes.

Import packages

import com.mapbox.api.isochrone.MapboxIsochrone
import com.mapbox.api.isochrone.IsochroneCriteria
import com.mapbox.geojson.FeatureCollection

Building the URL

Start by creating a new instance of the MapboxIsochrone object and use its builder to customize your API request. The options offered in the builder include choosing whether the API returns polygon areas and the colors of those polygon areas.

If you're using this API with the Mapbox Maps SDK for Android, setting true for .polygons(boolean) will return polygon coordinates that you can then use for FillLayer. Isochrone lines can be used with LineLayers.

MapboxIsochrone mapboxIsochroneRequest = MapboxIsochrone.builder()
.accessToken(MAPBOX_ACCESS_TOKEN)
.profile(IsochroneCriteria.PROFILE_DRIVING)
.addContoursMinutes(listOfIntegers)
.polygons(usePolygon)
.addContoursColors(listOfHexColorValueStrings)
.generalize(2f)
.denoise(.4f)
.coordinates(Point.fromLngLat(queryPoint.longitude, queryPoint.latitude))
.build();

API response

In the response to a request to the Mapbox Isochrone API, the isochrone contours are returned as a GeoJSON Feature Collection. More information about the response.

The API will return a FeatureCollection:

mapboxIsochroneRequest.enqueueCall(new Callback<FeatureCollection>() {
@Override
public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {

if (response.body() != null && response.body().features() != null && response.body().features().size() > 0) {

FeatureCollection featureCollection = response.body();

List<Feature> responseFeatureList = response.body().features();

}
}

@Override
public void onFailure(Call<FeatureCollection> call, Throwable t) {

Log.d(TAG, ("Request failed: %s", t.getMessage());

}
});



Was this page helpful?