How to avoid multiple calls to google direction API - google-maps

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

Related

What if I have no results to display on a map after calling Google Distance Matrix API

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

Can Google Maps API calculate route along multiple locations or journey legs?

I'm using the Google Maps API Web Services Directions API or the Distance Matrix API to find the travel distance and time between locations.
It seems that the API only supports calculation of the route between one origin and one destination. (In case of the Distance Matrix API, multiple combinations directly between origins and destinations are computed.)
My case is that I would like to know the route (really, just traveling time and distance) of a multiple-leg journey along a series (as in an ordered array) of locations.
So, considering four locations, A, B, C, D, I know how to compute the route between any pair, A-B, A-C, A-D, B-C and so on. I want to compute the route of A-B-C-D or A-C-D-B or A-D-B-Cand so on. I supply the route and the order of the legs, so I'm not asking to solve the Traveling Salesman Problem.
Is this possible with the Google Maps Directions API or Distance Matrix API?
Obviously, I can chain the locations myself, so ask for the routes of the individual legs in separate calls, and then add them together in the desired order: A-C + C-D + D-B becomes A-C-D-B. I'm hoping that it's possible with one call.
(I've looked for similar questions, but haven't found this exact one.)
Thanks to #geocodezip, the answer is to add 'waypoints' between the origin and the destination, as described in the documentation of the Directions API.
For example, the request https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA calculates the route between Boston and Concord via Charlestown and Lexington.
And the Traveling Salesman Problem is partly being solved as well, per
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.

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.

Look up walking time (calculated by Google maps) between two addresses (in a Google spreadsheet)

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.

Calculations involving bus routes

I am working with a college to develop their campus iOS app. One of the app's features is the ability to determine which of the campus bus routes are most applicable to getting to a destination (as well as a listing of when the bus arrives, etc).
If I have sets of long/lat data representing the stops of a route, what is the easiest way to determine the closest route to a long/lat destination point? I have over 10 roues to consider.
If you want to determine the closest point to a route, you can use the Distance to a Ray or Segment formula using a lat-lng as the reference point.
There is another option, if you are using a Google Map, because the Terms of Service require that the service be used in the context of a Google Map; you may want to consider the Google Maps Distance Matrix Servicedev-guide. The service allows you to submit a request with an origins property, which must be an array of google.maps.LatLng starting points and a destinations property, which must be an array of google.maps.LatLng ending points. The DistanceMatrixServiceapi-doc also allows you to define a TravelModeapi-doc, which may be one of: BICYCLING, DRIVING, or WALKING. It has the advantage over simple distance calculation, because it accounts for the natural activity of traveling from one point to another using the existing network of streets.