I’m trying to parse the response of a routing request into a MapBox route. The following code produces as successful response and allows me to make use of the round trip feature of the routing API:
List<String> point = new ArrayList<>();
String coord = locations[0].getLatitude() + "," + locations[0].getLongitude();
point.add(coord);
RoutingApi api = new RoutingApi();
RouteResponse res = api.routeGet(
point, false, "[KEY]", "en", true,
"foot", false, true, null, true, null, false, "round_trip", null, null,
null, null, (int) 3, (long) 1, null, null, null, null);
However I cannot figure out how to turn this response into a route using the MapBox functions? Can anyone please point me in the right direction?
I have tried to implement the hand crafted client, but i keep getting 405 errors (“Method not allowed”).
// Hint: create this thread safe instance only once in your application to allow the underlying library to cache the costly initial https handshake
GraphHopperWeb gh = new GraphHopperWeb();
// insert your key here
gh.setKey(KEY);
// change timeout, default is 5 seconds
gh.setDownloader(new OkHttpClient.Builder().
connectTimeout(5, TimeUnit.SECONDS).
readTimeout(5, TimeUnit.SECONDS).build());
GHRequest req = new GHRequest()
.addPoint(new GHPoint(51.9073273, -0.2260282))
.addPoint(new GHPoint(51.9373273, -0.2560282))
.setLocale(Locale.ENGLISH)
.setVehicle("car");
req.getHints().put("instructions", true);
req.getHints().put("calc_points", true);
GHResponse res = gh.route(req);
Can anyone tell me why this might be the case, i have tried all sorts of combinations, cutting it back to the simplest possible and i have made no progress.
I am still having trouble integrating the response from the Routing API into the Mapbox navigation endpoint.
Correct me if i’m wrong, but the navigation endpoint in the example SDK uses https://graphhopper.com/api/1/navigate/ to generate an encoded polyline which is used by the Mapbox API to generate the route, whereas the HC routing api uses https://graphhopper.com/api/1/route to generate a routing response which does not include the correct information to pass to the mapbox API.
How do i turn the response of the Routing API into something that can be used by the Navigation endpoint, without creating a second Routing request?
If you read /route use client-hc and convert to the format you need.
If you read /navigate you should be able to use any mapbox library, e.g. the Java library like we do in our Android demo.
How do i turn the response of the Routing API into something that can be used by the Navigation endpoint, without creating a second Routing request?
I do not understand this. The navigation endpoint is an endpoint to serve a client just like the /route endpoint ‘only’ in a different JSON format, it does not consume something from a source.
Thank you for your help, my question was probably a bit vague. After some sleuthing, I think i have found what i need, so I will post it here for anyone else.