Java

The Java Client for Next Billion Maps Services is a Java client library for the following NB Maps APIs:

  • [Directions API]
  • [Distance Matrix API]
  • [Geocoding API]
  • [Roads API]

Usage

Installation

<dependency>
<groupId>ai.nextbillion</groupId>
<artifactId>nb-maps-client</artifactId>
<version>1.5.0</version>
</dependency>
  • Gradle:
implementation 'ai.nextbillion:nb-maps-client:1.5.0'

Overview

GeoApiContext context = new GeoApiContext.Builder()
.apiKey("Bearer eyJ...")
.build();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
// Geocoding
String[] r1 =
GeocodingApi.reverseGeocode(context, new LatLng(13.00103968, 77.58919267)).await();
// Directions
DirectionsResult r2 = DirectionsApi.getDirections(
context,
new LatLng(13.01048975, 77.56078271),
new LatLng(12.92335211, 77.61877224)
).alternatives(true).await();
// Distance Matrix
LatLng[] origins = new LatLng[]{new LatLng(13.00595722, 77.60786971)};
LatLng[] destinations = new LatLng[]{new LatLng(12.99471296, 77.60752001)};
DistanceMatrix r3 = DistanceMatrixApi.getDistanceMatrix(context, origins, destinations).await();
// Matching
SnappedPoint[] r4 = RoadsApi.snapToRoads(
context,
new LatLng(12.97911156, 77.60315798),
new LatLng(12.97893807, 77.60364524),
new LatLng(12.97877372, 77.60414186),
new LatLng(12.97857284, 77.60475093))
.await();

API key

Transfer api key via http header:

GeoApiContext context = new GeoApiContext.Builder()
.apiKey("Bearer eyJ...")
.build();

Transfer api key via url query (https://api.nextbillion.io/direction?key=mykey):

GeoApiContext context = new GeoApiContext.Builder()
.apiKey("mykey")
.apiKeyInQuery(true)
.build();

Change host

GeoApiContext context = new GeoApiContext.Builder()
.hostName("https://custom.nextbillion.io")
.apiKey("Bearer eyJ...")
.build();