Google Maps API - Getting Street Coordinates - google-maps

Google Maps API has any way to get the street coordinates of an location?
Is simple: I just want to get the nearest street coordinate. To got this i need, for example, all coordinates that compose a street.
Are there something like this?

You may use the directionService.
Pass the given address(or location) as origin and destination to directionsService.route() and use the travelMode DRIVING . The response should contain the nearest street.
Demo: http://jsfiddle.net/doktormolle/W3VGN/

I found this (ReverseGeocoding in v3): https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding
Since this thread is old I suppose this could be useful.

These answers are all old, and Google has rearranged the maps API significantly since the answers.
In 2018, the best way to turn a location (long, lat) into a "point on road," is to use the snap-to-road or nearest-road service:
https://developers.google.com/maps/documentation/roads/snap
Note that this API charges a cent per API call, and can take up to 100 distinct points per call. If latency and complexity aren't problems, if you need to answer this question on a client, you could build a server that collects up to 100 requests from different clients, makes one request to Google, and then returns the request data back to the appropriate clients. (For this use, make sure to use nearest-road, not snap-to-road.)
Also, currently, Google Maps has a $200 per-month statement credit available, which may make smaller uses of this API not actually end up costing much (or anything at all.)

Related

Can you get an ideal route of multiple destinations using a single API call?

I'm trying to see if there's a way in a single API call to find the ideal route, order not mattering, between X destinations.
For example, the program has 3 destinations, Jeff's house, Amy's house, and Valerie's house. Don't really care the order we go in, but we'd like to visit each house with the least amount of driving.
Right now, I have it set up such that we try every ordering of destinations, and settle on the one with the fastest time. But having so many API calls seems inefficient, but I can't see a way in the API to do what I want. Is what I want presently possible in the google maps API?
You can use Waypoints in Directions API web service which returns a route that includes pass throughs or stopovers at intermediate locations.
By default, the Directions service calculates a route through the
provided waypoints in their given order. 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.
Sample request:
https://maps.googleapis.com/maps/api/directions/json?
origin=Adelaide,SA&destination=Adelaide,SA
&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA
&key=YOUR_API_KEY
Note that requests using waypoint optimization are billed at a higher rate.
If you will be using client-side Maps JavaScript Directions Service. Refer to this documentation and example.
Hope this helps!

Google Maps -> Making a circular route based on given distance?

Trying to avoid reinventing the wheel here.
Anyone knows of any API that lets one create a route that starts and ends at the user's position, given as parameter the distance required for the route?
For example, you want to take a walk. A walk of a total of 5KM from home and back to home. Any API that will work with Google Maps to offer routes?
Thanks, as always.
You can implement this with the use of Google Maps API Directions Service which receives direction requests and returns computed results.
Furthermore, with this API, you can create a route that starts and ends at the user's position by Using Waypoints in Routes .
As mentioned,
Travel time is the primary factor which is optimized, but other factors such as distance, number of turns and many more may be taken into account when deciding which route is the most efficient.
Please note, however, that the use of Directions service must be in accordance with the policies described for the Google Maps Directions API.

Find closest point using Google Maps API

I have a number of target points on the map and a source location. I need to find the target point closest to the source location. The trick here is that "closest" means the shortest route. I can't use a simple crow fly distance.
This is essentially a one-to-many routing problem. I can get the answer by running a routing API call for each pair of points but that would be too slow and will blow up API usage.
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)?
If yes, then what are the limits to the number of points, the request frequency, etc?
If no, is there another service that can do it?
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
You should take a look to Distance Matrix Service
You can specify a starting point and an end point (even intermediate waypoints), then get the distance in kilometers / miles by route.
To answer your questions :
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)
Yes you can, just use the service given below
If yes, then what are the limits to the number of points, the request frequency, etc?
To quote the Usage limits and requirements :
The following usage limits are in place for the Distance Matrix service:
Maximum of 25 origins or 25 destinations per request; and
At most 100 elements (origins times destinations) per request.
Requests are also rate limited. If too many elements are requested within a certain time period, an OVER_QUERY_LIMIT response code will be returned.
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
I'm not sure what you really want, but you can define a point as "source location", then load it (from SQL, KML etc...), then load the targets and call the service to find which one is the closest.

Detect the nearest transit stop from the given location

I need to get all the nearby public transit information within certain distance from a given location. The type of public transit can be either bus, train, etc..
Here is what I meant:
If I use Google Map to query "Transit Stop near a Location (e.g. Bugis Street Singapore)", then it will return us all the nearby Transit Stop that I want. Like the one shown in the picture. But I need its API to get those details out. (such as bus service No, bus stop ID, etc. as shown in the picture). But I couldn't found any.
Here is what I've tried
I have tried using the Google Map Nearby Place API to search for a place with the type of transit_station, bus_station, train_station,etc... But they all return Zero Result. I could only use this API to search for Nearby Place of Interest, but not nearby transit.
I've also check Google Transit API, but I only found API to insert transit data to Google but Not to extract it out. I think Google didn't publicize the transit API yet.
Additional Information
I have check the site Gothere.sg. And confused How? because they able to detect the nearby transit. Is it only because they specify the direction "From-To".
I have read a pretty similar question on Detecting nearby transit. Perhaps It is not yet possible if we use Google APIs.
But nothing is impossible for me
Last Resort
As Last resort, I also check with the provider, publictransport.sg. I hack around with the API. And found out that it can provide me with a transit stop with some coordinate. But it lack a nearby API which found on Google Map.
So one workaround I could think of at the moment, is to use the provider in this case was publictransport.sg which give me the Stop ID and its coordinate. To do this, First, I have to translate the location name using the Google GeoCoding API into Coordinate then I have to create my own nearby calculation to find the nearby station by comparing the searched Coordinate against all the station coordinate that the provider have.
Now, it is possible for me, but very painful :-)
Back to the Question:
Is there a way to retrieve all transit stop data from a given location (either using Google Maps API or Any other API)? and How did u do that?
Thanks
At least thanks for reading my lengthy question. I appreciate any help from you.
Well, you could use the places-API to find the nearest transit-stops, it works fine for me for the given location.
Just do a request with the parameters:
location (latlng-object of the given location)
radius(radius to search for in meters)
types(array of valid types, e.g. ['bus_station','subway_station'])
Checkout the fiddle: http://jsfiddle.net/doktormolle/aZrvs/
For retrieving further details(bus service No, bus stop ID) I don't have any good idea right now.
There should be a way, those data on maps.google.com will be retrieved by using AJAX, so there is a ressource. But as long as there is no public API to fetch those results it would not be legal to use this ressource.
Adding &output=json to your initial query (http://maps.google.com/maps?q=transit%20stop%20near%20New%20Bugis%20Street%20Singapore&output=json), is not a legal way to get this information?
You can still enumerate all of Bus Service Number, Bus Stop ID (Station Names) after getting the google-places-api details, as #Dr.Molle: said.
Open the webpage of detail['result']['url'], and then XPath the string of bus ID list.
Below is an example to get Taipei's bus Info around a location (latitude, longitude). More detail implementation see https://github.com/MikimotoH/gisTools/blob/master/google_place.py
places = get_web_json(
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' +
'key=%s&location=%f,%f' % (apikey, lat, lng) +
'&rankby=distance&language=zh-TW&types=bus_station')
if places['status'] == 'OK':
for result in places['results']:
placeid = result['place_id']
detail = get_web_json(
'https://maps.googleapis.com/maps/api/place/details/' +
'json?key=%s&placeid=%s' % (apikey, placeid) +
'&language=zh-TW')
station = detail['result']['name']
loc = detail['result']['geometry']['location']
buspage = get_webpage(detail['result']['url'])
tree = lxml.html.document_fromstring(buspage)
bus_elm = tree.xpath("/html/body/div[1]/div/div[4]/div[4]/div/div/div[2]/div/div[2]/div[1]/div[2]/div/div/div[2]/div/table/tr/td")[0]
buses = list(filter(lambda s: len(s.strip()) > 0,
bus_elm.text_content().strip().split()))
yield (station, float(loc['lat']), float(loc['lat']), buses)
The Transitland APIs can answer your question. For example, try using the Transitland v2 REST API stops endpoint like this:
https://transit.land/api/v2/rest/stops?lat=xxx&lon=xxx&radius=1000&apikey=xxx
More information on the endpoint parameters and response at https://www.transit.land/documentation/rest-api/stops

Geocoding with Google Maps API - accuracy and limitations

It is easy to use the Google Maps API to find a specific street address and return the latitude and longitude. For example, link.
However, it appears that typing in the name of a specific location, for example a park, causes problems. Often these don't have a specific street number (at least, not easily findable). Despite the fact that Cadigal Reserve is located at the same address as in the link above, if I enter that as part of the query string and remove the street number, the results become rather useless: link
Typing this directly into maps.google.com easily finds the park itself (and of course, you could then find the latitude/longitude by looking in the URL).
Is there not any way of using the Google Maps API to geocode a park location like this?
It is important to understand that geocoding is not an exact science. The recommended practice if you have addresses that you know should geocode to a specific location is to build a cache and use local (client-side) geocoding.
In version 2 of the api you would build your own client-side cache that contains pre-computed geocoder responses by extending the GeocodeCache. Once a cache is defined, you would call the setCache() method and away you go. This is pretty much explained here:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Caching
However, AFAIK GeocodeCache was removed in V3 of the api...
So, I would suggest implementing your own client -side caching-strategy of known addresses and their corresponding coordinates. When your application receives a geocode request for a known address the response would come from your cache (rather than Google's geocoding servers).
Failing all that you can always use a payed geocoding service that, in theory, will have a much more accurate dataset (as well as a higher limit on requests, etc).
Finally, you should also take a look through the Geocoding Strategies document as it gives a good handle on some of the issues here.