Generating a map in android - 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

Related

Route optimization using Google Direction API for Mobile App

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.

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!

I want to retrieve the latitude and longitude of a location shown in google map route between two locations

I have lat and long of some locations in JSON. I want to spot whether these locations are present in a route shown by google maps.
Here are the steps I'd consider to achieve the effect you want:
Query for a DirectionResponse https://developers.google.com/maps/documentation/directions/intro#DirectionsResponses
For each polyline of each step of each leg, test whether your locations are close to the line. For simplicity you can also use the overview_polyline. Unfortunately this is not simple to do out-of-the-box using the Maps API alone. Check this thread for inspiration on a manual implementation. Find a point in a polyline which is closest to a latlng
Alternatively, convert the polylines to GeoJSON, and process using a spatial library such as JSTS or Turf. E.g. the latter provides a pointOnLine function.

How can I use Graph data structure to generate route with exact distance using Google API in Android?

I need help with my final CS Project. Basically, I have to write an Android app that the user can specify a starting location and distance desired. It is going to generate a route that is exactly the distance of the input that the user can walk/ run and brings the user back to the starting location, using the Graph data structure and Google API.
I have my Google map and Android app but I’m not sure where to start with storing data using Graph ( I'm not sure if I should even use this data structure) and how to calculate the distance input. Any bits of advice/ help will be appreciated!
Okay your question is very tricky but still let me answer from what I got.
Use google map api, google places api, place picker or id and google maps json api for routes and distance.
let's take an example like you want walk or run 4kms from your places and comeback.
Case 1: if you want to opt for the same route from which you went to come back.
like you went from a-b then again you are coming bak from b-a.
for this case you can use Google maps geofencing and get the place inside a minimum raidus and make an algo to get the distance from your places.
if teh distance is half of the distance from your places then pick the most approximate place.
Use google maps json to get the places distance and google place picker for the location of nearby location object.
Case2: If you donot want to come from the same route through which you went
by, then select the nearest location object and get the longest route and follow
the same algo and procedure to get the distance.

Is it possible to use Google MAP API to locate nearest universities and schools when the user type his current location?

I am making an android application and I am thinking instead of having a database and input numerous universities and schools in our area, is it possible to use google map instead? For the user to just type the location and identify the nearest college and universities base on the location the user typed by the use of google map?
I'm not sure if there are any search features built into the Android SDK, but you can certainly still use the Place Search API.
The following example is a search request for places of type 'university' within a 500m radius of a point in Sydney, Australia:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?type=university&location=-33.8670522,151.1957362&radius=500&key=YOUR_API_KEY
You simply need to specify the type as university or school. See here for other supported types.
Use the google place api as follows
https://maps.googleapis.com/maps/api/place/nearbysearch/json?type=university&location="current lattitude","current longitude"&radius=500&key=YOUR_API_KEY
for more info visit https://developers.google.com/places/web-service/search.

Categories

Resources