I want to show the driving route between two locations in my android app. I want to draw the route only on top of road segments.
There are several answers on stack o
For me, I used OSM to get directions as geojson then draw the route on Google map using google maps utils
first
// build.gradle
dependencies {
implementation 'com.google.maps.android:android-maps-utils:0.5'
}
// in maps Activity
// mMap is Google map
// geoJsonData is the returend json object from directions api
// which in my case is OSM
GeoJsonLayer layer = new GeoJsonLayer(mMap, geoJsonData);
// now you can add the layer to the map
layer.addLayerToMap();
// congrats you draw the road between two points now :)
For more information check this Google Maps Android GeoJson Utility.
Happy Coding