I have a list of latitude and longitude in my app, Using Google direction API or using any other Google API is it possible to arrange the latitude and longitude based on optimal route with time.
While googling I do find this API https://developers.google.com/maps/documentation/directions/start#sample-request
But in this API google asking to provide origin and destination not list of geocodes. Is there any way I can achieve this using list of Geocodes.
Use more specific documentation: https://developers.google.com/maps/documentation/directions/intro#optional-parameters. You need waypoints
optional parameter with place names:
https://maps.googleapis.com/maps/api/directions/json? origin=Boston,MA&destination=Concord,MA &waypoints=Charlestown,MA|via:Lexington,MA &key=YOUR_API_KEY
or latitude/longitude:
https://maps.googleapis.com/maps/api/directions/json? origin=sydney,au&destination=perth,au &waypoints=via:-37.81223%2C144.96254%7Cvia:-34.92788%2C138.60008 &key=YOUR_API_KEY
or encoded polyline:
https://maps.googleapis.com/maps/api/directions/json? origin=sydney,au&destination=perth,au &waypoints=via:enc:lexeF{~wsZejrPjtye@: &key=YOUR_API_KEY
And:
Optionally, you may pass optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the traveling salesperson problem.)
Also you can use Java Client for Google Maps Services as wrapper for Directions API requests.