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.

Author: JunDev, 2018-05-31

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(...)
 0
Author: SergeyBukarev, 2018-05-31 14:48:09
 0
Author: Serge Markov, 2018-05-31 14:41:26