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.
Related
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!
I would like to develop a service, using Google Distance Matrix API, where a user can enter their current location and a map will be displayed showing how many other users from their group have addresses in the same general area. For privacy reasons, I do not want to show any other details (location, name, address etc.) of those other users just the number of people.
In order to ascertain this information I was intending to make a call to the API and displaying under the map of their area a message like "There are 5 other people within a 3 minute drive of your address".
Can anybody tell me whether this meets the API limitation:
The Google Maps Distance Matrix API may only be used in conjunction with displaying results on a Google map. It is prohibited to use Google Maps Distance Matrix API data without displaying a Google map
If my requirements of the API are not acceptable, could anybody suggest another publicly available API that I could use in its place?
Thanks!
Yournavigation Api gives you distance from given points.
Try this request example.
You can find their usage policy here.
They said that there are no limitations on usage, except those regarding overload:
The routing API is open and freely available for everyone under the condition that you don't overload the server. Overloading the server in this context means: more then 1 request per second for sustained periods of time. Bursting multiple requests for short time-periods is not a problem though
We’ve a requirement where we need to calculate “Driving Time” from location A to location B, also there could be several way points between location A & B. Currently we’re managing this requirement successfully using Google Direction API.
Now we’ve a situation where we’ve to calculate this driving time for multiple vehicles, situated at different locations. Which means start point will vary but waypoints and destination will remain same.
Now do I need to call direction API for each vehicle separately or is there any other API by which I can obtain this information in single call.
I remove a segment after you pass it, solution
If minimum distance from your location to segments, I will call to google APIs again
I have a Google spreadsheet with one column of physical addresses, and I want to have a second column be the time in minutes to walk between the address in column 1 and a second address (as determined by Google Maps). Any recommendations on how to accomplish this task?
From my understanding of the Google Maps terms of service, they:
don't like people using their service as a "batch geocoder". This means that
you will need to throttle your requests (place delays between each successive request, to avoid the OVER_QUERY_LIMIT error)
it is against the terms of service to use the geocoder (and maybe the distance service) without displaying a map graphic
If you still want to proceed,
you need some way of extracting the address from your spreadsheet. I think there's a Google docs API that will help you do that. I also found some custom Javascript code that does that for you easily. I don't have a link anymore :(
once you have the addresses readable from the Google Maps Javascript API, you can call the distance or directions API to get the walking distance
then you need to save that back to the spreadsheet.
It sounds like a possible application for the Distance Matrix Service.
But you can only use it if you will be displaying a map
Use of the Distance Matrix API must relate to the display of
information on a Google Map; for example, to determine
origin-destination pairs that fall within a specific driving time from
one another, before requesting and displaying those destinations on a
map. Use of the service in an application that doesn't display a
Google map is prohibited.
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.)