Java and Android client for the GraphHopper Directions API
Java Other
Latest commit 667ae86 Jan 19, 2017 @boldtrn boldtrn committed with karussell Added exited parsing to the client (#43)

Java and Android client for the GraphHopper Directions API

You can refer to this client in your pom.xml via


Please search maven for the latest version.


Apache License 2.0


GraphHopperWeb gh = new GraphHopperWeb();
// insert your key here
// change timeout, default is 5 seconds
gh.setDownloader(new OkHttpClient.Builder().
                connectTimeout(5, TimeUnit.SECONDS).
                readTimeout(5, TimeUnit.SECONDS).build());

// specify at least two coordinates
GHRequest req = new GHRequest().
   addPoint(new GHPoint(49.6724, 11.3494)).
   addPoint(new GHPoint(49.6550, 11.4180));
// Set vehicle like car, bike, foot, ...
// Optionally enable/disable elevation in output PointList, currently bike and foot support elevation, default is false
req.getHints().put("elevation", false);
// Optionally enable/disable turn instruction information, defaults is true
req.getHints().put("instructions", true);
// Optionally enable/disable path geometry information, default is true
req.getHints().put("calc_points", true);
// note: turn off instructions and calcPoints if you just need the distance or time 
// information to make calculation and transmission faster
// Optionally set specific locale for instruction information, supports already over 25 languages,
// defaults to English

GHResponse fullRes = gh.route(req);

if(res.hasErrors()) {
   // handle or throw exceptions res.getErrors()

PathWrapper res = fullRes.getBest();
// get path geometry information (latitude, longitude and optionally elevation)
PointList pl = res.getPoints();
// distance of the full path, in meter
double distance = res.getDistance();
// time of the full path, in milliseconds
long millis = res.getTime();
// get information per turn instruction
InstructionList il = res.getInstructions();

Matrix API

GraphHopperMatrixWeb matrixClient = new GraphHopperMatrixWeb();

GHMRequest ghmRequest = new GHMRequest();

// init points for a symmetric matrix
List<GHPoint> allPoints = ...;

// or init e.g. a one-to-many matrix:
for(GHPoint to : toList) {

MatrixResponse response = matrixClient.route(ghmRequest);
GHMResponse singleRsp = response.get(fromIndex, toIndex);

Build Latest Development Version

git clone
cd client
mvn -DskipTests=true clean install

# now execute the test and set your key
mvn -Dgraphhopper.key=[YOUR_KEY] clean test verify


It is important to use this client not on the main thread of Android as it could block the app. See issue 7 for more information.

Android Alternative

The OSM OSMBonusPack also has an Android client written from the community. It also supports online map tiles. You can see this code in action in Geopaparazzi, OSMNavigator and more

Route Optimization API

If you setOptimize("true") then the locations will be optimized according to the best overall route. For more advanced features like multiple vehicles and capacity restrictions etc. you need to call the Route Optimization API. The client for the Route Optimization API is located in the folder "route-optimization".


See the examples on how to use this client.


The route optimization client is in the maven central repository, thus you can just reference it in your pom like:



If you want to build it from source please follow the guide for java here.



See the tests on how to use this client.

Generate from Swagger

Download Swagger Codegen CLI

java -jar swagger-codegen-cli-2.2.1.jar generate -i geocoding_swagger.yaml -l java -o geocoding -c geocoding-config.json