Directions SDK
What is it?
It's a library written in Kotlin to utilize Google Directions API calls and convert response to data classes.
How do I use it?
Add dependency
allprojects {
repositories {
...
maven { url 'https://dl.bintray.com/rozkminiacz/Directions-Android-SDK' }
}
}
implementation : 'me.rozkmin.directions:core:1.0'
Create instance of DirectionsApiClient:
class AnotherBoringMapActivity : Activity(){
val directions : Directions by lazy {
DirectionsSdk(getString(R.string.google_directions_key))
}
}
Transit options
You can specify severalDirections API request parameters:
val transitOptions = TransitOptions(
mode = MODE.WALKING,
whatToAvoidArray = arrayOf(AVOID.FERRIES, AVOID.HIGHWAYS))
Request route between points
class AnotherBoringMapActivity : Activity(){
fun getSuggestions(from: LatLng, to: LatLng){
directions.getSuggestions(
origin = Position(from.latitude, from.longitude),
destination = Position(to.latitude, from.longitude))
.subscribe({ t : GeocodedResponse ->
//process routes
},{
//error
})
}
}
Retrieve route steps:
fun processData(geocodedResponse: GeocodedResponse){
val stepStart: Position = geocodedResponse.routes[0].legs[0].steps[0].start
val stepEnd: Position = geocodedResponse.routes[0].legs[0].steps[0].end
}
Make use of detailed polyline
fun processData(geocodedResponse: GeocodedResponse){
val positions: List<Position> = geocodedResponse.routes[0].overviewPolyline.getDetailedWaypointsPositions()
}
I want to improve this library!
Sure! Pull requests are welcome! Any reasonable extension will be added.