this is couroutines implementation, for RX see https://github.com/rozkminiacz/DirectionsSDK
It's small library written in Kotlin to utilize Google Directions API calls and convert response to PolylineOptions, ready to add to GoogleMap.
Well, you don't have to. But if you already reading this - consider using it if you don't want to parse nested jsons by yourself.
That's simple. First - add dependency to your build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation : "com.github.rozkminiacz:GoogleMapsPolyline:1.0"
You must also provide google maps core dependency:
implementation : "com.google.android.gms:play-services-maps:11.8.0"
class AnotherBoringMapActivity : Activity(){
fun createClient() {
directionsApiClient = DirectionsApiClient(
apiKey = getString(R.string.google_directions_key))
}
}
class AnotherBoringMapActivity : Activity(){
fun requestRoute(from : LatLng, to: LatLng){
directionsApiClient.getRoutePolylines(origin = from, dest = to) {
//do something with list of PolylineOptions
//remember, that you are not on main thread here
}
}
}
You can add some customization to Directions API request, just look at TransitOptions class. You can specify transit mode, and what to avoid during route planning.
Yeah! That's possible! Just implement Converter<GeocodedResponse?, List> and you are ready to go!
class AnotherBoringMapActivity : Activity(){
fun configure(){
val myConverter = object : Converter<GeocodedResponse?, List<PolylineOptions>> {
override fun convert(from: GeocodedResponse?): List<PolylineOptions> {
//
}
}
val directionsApiClient = DirectionsApiClient(
apiKey = getString(R.string.google_directions_key),
polylineConverter = myConverter)
}
}
Look at example in this repo, in app directory.
Sure! Pull requests are welcome! Any reasonable extension will be added.