Distance API with Android SDK

Get distance, duration and path polyline for a pair of origin and destination, based on the recommended route between those two points for a specified travel mode.

  1. Building Directions Request
  2. Drawing a route

You can calculate directions by using the DistanceService. This object is an interface to the Route endpoint of Woosmap Distance API. This service compute travel distance, time and path for a pair of origin and destination.

This guide assume you already know how to add the SDK as a dependency and configure an API Key.
If you never used Woosmap Android SDK before, we strongly recommend to start with the Step by Step Guide first.

Building Directions Request

To use distance in the Woosmap Android SDK, instantiate a DistanceService and call distanceService.getRoute() to initiate a request to the Route endpoint of Woosmap Distance API, passing it at least the origin/destination LatLng. You can find the full documentation of this endpoint in the API documentation.

kotlin
        val distanceService = DistanceService()
val routes = distanceService.getRoute(anOrigin, aDestination, alternatives = true)

    

Drawing a route

To draw a route you can simply instantiate a DistanceRenderer with your map and pass it a route response.

kotlin
        val distanceRenderer = DistanceRenderer(mapView)
distanceRenderer.plotRoutes(routes)

    
Was this article helpful?
Have more questions? Submit a request