Route optimization using Google Direction API for Mobile App - android

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.

Related

Google Maps: open URL by coordinates but show the location name

I've been trying to open Google Maps (specifically on Android, but not necessarily) from a coordinates URL, such as
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754
But when the map opens, I want it to show the location name such as "Tower Bridge". Not the coordinates 51.5055,-0.0754
I have tried something like
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=Tower+Bridge
with no luck. When maps opens it shows the coordinates, not the place name.
I am okay with either "injecting" the location name (something like https://....&location_name=Traitors+Gate), and/or with maps revealing the location name (reverse geocoding) from the coordinates.
Motivation: Coordinates are more accurate and less ambiguous than location names. For example, there is Jerusalem, OH and there is Jerusalem, Israel, which is half a world away. Or, "Palais de Louvre" which is just one building but one huge building over four streets, with multiple entrances. Coordinates solve those issues, but they are not "Human readable". You can't present "49.3697,0.8711" to a user and expect them to recognise the Omaha Beach.
Thanks
Unfortunately, the Google Maps URLs doesn't support this kind of sending labels. You should send a valid place ID value in order to get correct title of the place in Google Maps app.
You will need one additional step to do this. Execute reverse geocoding request for coordinate and get a place ID.
https://maps.googleapis.com/maps/api/geocode/json?latlng=51.5055%2C-0.0754&language=en&key=YOUR_API_KEY
This will return a place ID ChIJlRsEuUgDdkgRSM7ciIhVooM of Tower Bridge. Have a look at this example in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D51.5055%252C-0.0754
There is a Java client library for Google Maps API Web Services that you can find on GitHub:
https://github.com/googlemaps/google-maps-services-java
You can use this library to execute geocoding requests, alternatively you can also use Places API nearby search to get the nearest place. Note that web services require a different API key, because they don't support Android app restriction that you use in API key for Maps Android API.
Once you get a place ID value just create Google Maps URLs link. E.g.
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=ChIJlRsEuUgDdkgRSM7ciIhVooM
I hope this helps!

API to determine whether the co-ordinate given is a road or a building?

We are creating an app on traffic monitoring and handling congestion. We want to know if there is a way we can find out about the place if it's a road or building using the Co ordinates
You can use The Google Maps Geocoding API's reverese geocoding service.
Example of Reverse Geocoding
The following query contains the latitude/longitude value for a location in Brooklyn:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY

how to check a point is accessible through road (Android)

i'm getting latitude and longitude of a location, I want to know the roads connecting to that location and whether it is land or water
I tried one google map api which is not helping to get the information i want.
http://maps.google.com/maps/api/geocode/json?latlng=40.7127,74.0059&sensor=true
Another SO answer pointed out two possible workarounds:
You can use Google Maps Reverse Geocoding . In result set you can determine whether it is water by checking types. In waters case the type is natural_feature. See more at this link http://code.google.com/apis/maps/documentation/geocoding/#Types.
You can detect waters/lands by pixels, by using Google Static Maps. But for this purpose you need to create http service.
You can use the Google Maps Geocoding API which does exactly that: http://code.google.com/intl/da-DK/apis/maps/documentation/geocoding Take a look at the "Reverse Geocoding" section

Generating a map in android

if i'm given a set of points(latitude,longitude) how can i generate a map with them between the points such that route generated is optimum.
i have no clue about it and so I've not mentioned the code along with it.
my purpose is to extract the latitudes and longitudes of points from a table in my local database and then generate a map with it .
I would use the Google Directions API to determine routes between each of the geolocations. Here is an introduction to Google Directions. Part of the way down there is a, "Use Waypoints in Routes", which allow you to specify one or more addresses to determine a route.
If you need help getting started with Google Maps API, here's an introduction.
What you are looking for is, can be acheived by google maps api, using waypoint parameter
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|via:Lexington,MA&key=API_KEY
in waypoint, either you can supply the location name or geo coordinates which should be delimeted by | incase you have multiple points, please follow this link for more detail about its usage.
https://developers.google.com/maps/documentation/directions/#DirectionsRequests

Getting the nearest street/road coordinates in android

In javascript, using Google maps apis we specify options such as google.maps.TravelMode.DRIVING. Do we have any equivalent for TravelMode in android? I couldn't see anything in android.location.LocationManager or android.location.Criteria
I've thought of following options:
Using some TravelMode alternative, get coordinates approximated to nearest street/road.
Alternatively, (Not preferred as it will be slow) get the coordinates normally and then probably send it to some google api(This will be pretty slow as there are many points) and get the coordinates corrected to the nearest street coordinates. Or in case if there exists some (google-maps) javascript framework, it may be used to get corresponding street coordinates.
Edit1:
I've also looked into this. and hence into android.location.Geocoder. The getFromLocation in this class seems to do most of the work. However, I'm afraid, of an additional delay while acquiring the nearest address.
If you are referring to Directions Service, then it uses Google Directions API internally as stated in the overview:
This object communicates with the Google Maps API Directions Service which receives direction requests and returns computed results.
As there is no native API for Android yet, I suggest using Directions API directly.
See my answer here.

Categories

Resources