How do I draw a route, along an existing road, between two points?

前端 未结 4 618
孤街浪徒
孤街浪徒 2020-11-27 03:18

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

4条回答
  •  情深已故
    2020-11-27 03:30

    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

提交回复
热议问题