Google map android sdk optimal route between many points
I'm making an android app there comes an array of objects (10-30 pieces) on the Google map and you need to display them on the map and build the optimal route between these objects. I haven't worked with Google map before and I can't find an example or a description of how to do it.
2 answers
I think to plot the optimal route with n points, you need to build a route between them in pairs. To build a route between two points on the map, you need to call the google api method to build a route between two points.
"https://maps.googleapis.com/maps/api/directions/json?" + parameters;
Where parameters is a string that is formed like this
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
String parameters = str_origin + "&" + str_dest + "&sensor=false;
In the response, you will get an array of points. You simply connect these points to each other in GoogleMaps using the map method
map.addPolyline(...)
Just display the points on the map, in general, is not difficult https://developers.google.com/maps/documentation/android-sdk/polygon-tutorial
However, routing, step-by-step navigation is a commercial API https://cloud.google.com/maps-platform/routes/
Perhaps this will help you https://stackoverflow.com/questions/24531391/is-it-possible-to-create-turn-by-turn-gps-navigation-app-on-android-using-google