Quantcast
Channel: maps for developers - Medium
Viewing all articles
Browse latest Browse all 2230

Optimize trips using Mapbox Android Services v2.1

$
0
0

Mapbox Android Services (MAS) provides an out of the box solution for adding Directions, Geocoding, Map Matching, and more inside your Java and Android applications. The latest v2.1 release of MAS now adds the Optimization and Matrix APIs along with an abundance of other improvements to give your users an even better routing & navigation experience.

Optimization API

If you need to provide your delivery fleet with the optimal order for making several stops, the new Optimization API returns multi-stop itineraries based on travel time. Feeding in a list of coordinates and making a request returns a route similar to the Directions API response. You’ll also receive turn-by-turn guidance and accurate ETA predictions for each stop along an itinerary.

Mocking a user traversing along the optimized route.

// Build a list of the trip stops.List<Position>tripStops=newArrayList<>();tripStops.add(Position.fromCoordinates(-73.99322,40.74302));tripStops.add(Position.fromCoordinates(-73.97920,40.74451));tripStops.add(Position.fromCoordinates(-73.99179,40.75979));tripStops.add(Position.fromCoordinates(-73.97144,40.76369));tripStops.add(Position.fromCoordinates(-73.98812,40.75906));// Build the Optimization API request.MapboxOptimizedTripsclient=newMapboxOptimizedTrips.Builder().setProfile(DirectionsCriteria.PROFILE_DRIVING).setAccessToken(<youraccesstokenhere>).setCoordinates(tripStops).build();// Execute the API call and handle the response.client.enqueueCall(newCallback<MapMatchingResponse>(){@OverridepublicvoidonResponse(Call<MapMatchingResponse>call,Response<MapMatchingResponse>response){// Draw the route line onto the map.drawLine(response.body().getTrips().get(0).getGeometry());}...

Matrix API

Starting in MAS v2.1, we’ve deprecated the Distance API previously offered and replaced it with the improved Matrix API. This new API returns estimated route durations between coordinates as an array. The coordinates provided can either be a destination or a source and are automatically snapped to the road grid. Driving, cycling or walking profiles are supported and you can make up to 25 coordinates in a single request. Building a request and executing it is almost identical to other APIs offered in MAS:

List<Position>positions=newArrayList<>();positions.add(Position.fromCoordinates(d-122.42,37.78));positions.add(Position.fromCoordinates(-122.45,37.91));positions.add(Position.fromCoordinates(-122.48,37.73));// Build the requestMapboxDirectionsMatrixclient=newMapboxDirectionsMatrix.Builder().setAccessToken(<youraccesstokenhere>).setProfile(DirectionsCriteria.PROFILE_WALKING).setCoordinates(positions).build();...

We’ve also finalized the first generation of the Android Navigation SDK; this means the SDK has been moved to a separate Maven dependency and is no longer located inside MAS. This change comes with several improvements, like making the RouteProgress class immutable and allowing us to add in new APIs. Under the hood, the SDK logic has been improved and includes an OffRouteListener and rerouting capabilities.

Getting started

Aside from the features listed above, MAS v2.1 also brings support for the Directions API annotation and weight query parameters, LocationEngine improvements allowing you to set more provider options, and significant bug fixes too. Check out the new Android documentation and make sure to bump your project dependencies to 2.1 today!


Viewing all articles
Browse latest Browse all 2230

Trending Articles