I want to find a travel time (including traffic) between two addresses.
Inputs - origin, destination, arrival time, mode of transportation, traffic model (pessimistic, optimistic, best guess)
Output - Travel time
It looks like the Google Distance Matrix API is the API I should be using for this except that I am not able to add an input of arrival time for driving. I am prompted to add a departure time. When the transportation mode is transit I am able to enter an arrival time.
Is this a limitation of the distance matrix API? Is there a paid for version or another work around for this?
As of today (January 6, 2019) arrival time for driving is not supported. Here is the relevant portion of the help file for the API's directions method:
:param arrival_time: Specifies the desired time of arrival for transit
directions. Note: you can't specify both departure_time and
arrival_time.
:type arrival_time: int or datetime.datetime
The key being that arrival time is only used for transit directions and not driving directions. When I use mode='driving' and an arrival_time, I get and error that ends with:
raise googlemaps.exceptions.HTTPError(response.status_code)
googlemaps.exceptions.HTTPError: HTTP Error: 400
When I change this to a departure_time, the function call works just fine.
Explicit answers to the questions:
Is this a limitation of the distance matrix API?
Yes.
Is there a paid for version or another work around for this?
No. Your only option is call the API with a guess for the departure time, find the travel time and then iterate until the arrival time converges.
instead of using the google direction matrix try to use google map direction API, it will give you best results with the time distance and traffic update, see GOOGLE MAP DIRECTIONS API docs.
You need to use the Google map distance matrix API, which get input as source latitude, longitude and destination latitude, longitude. It will return the json file contains the source address, destination address, distance in km and time with traffic and without traffic.Below is link follow it
https://developers.google.com/maps/documentation/distance-matrix/intro
There is also a limit of this API, it allows only 2500 hits per day
Related
The Google Maps API docs as well as all questions I have found on Stack Overflow all state that departure time must be included to return traffic duration. However, my application requires the use of arrival time and not departure time.
The docs state that one can pass either departure or arrival time, but this is not mentioned in relation to duration_in_traffic. Is it possible to pass arrival time instead of departure time and still receive the duration_in_traffic? Maps itself does this, I don't see a reason for Google's API to be any different.
This is not currently possible, but there is a long-standing feature request to have this feature added. You can star the issue to receive updates and show Google that there is additional interest.
I have address(city,state,country,zip) and want to get TimeZone , latitude and longitude in single Google API call , i see google provide TimeZone api which accepts latitude and longitude and returns TimeZone but that requires two api call , first is to get location ( lat/lng) and second call to get TimeZone from location , not sure if google provide such api which can solve this problem in single call.
I believe you can at least get the number of minutes this place's current timezone is offset from UTC together with its coordinates using Place Autocomplete. You can look for the logs 'utc_offset' under 'result' property.
The response includes the following:
geometry: The place's geometry-related information. This includes:
location provides the latitude and longitude of the place.
viewport defines the preferred viewport on the map when viewing this place.
utc_offset: contains the number of minutes this place’s current timezone is offset from UTC. For example, for places in Sydney, Australia during daylight saving time this would be 660 (+11 hours from UTC), and for places in California outside of daylight saving time this would be -480 (-8 hours from UTC).
You can use Places Autocomplete as #rafon said. But you should use setFields method and add utc_offset_minutes.
Like that autoComplete.setFields(['utc_offset_minutes'])
You can not get utc_offset_minutes from geocoding api.
Given an origin and destination, I want to get the location x minutes into that route; is this possible through the Google Maps API?
Not directly, no.
The closest you could easily get is that you know what legs would have been completed in the required time, and how much of the current leg remains.
Calculating the location of the point that much time into that leg would be more tricky.
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.
I found that sometimes google directions service returns zero results with transit transort mode. At the same time https://maps.google.com/ can finds rout for the same adresses.
Pls try:
http://maps.googleapis.com/maps/api/directions/xml?origin=Uzhhorod&destination=Zhytomyr&sensor=false&departure_time=1351544080&mode=transit
Returns ZERO_RESULTS, however Google Maps itself returns many results.
http://maps.google.com (->directions)
Origin: Uzhhorod
Destination: Zhytomyr
Departure at: 10/29/12 20:38 (1351544080 - Unix Time stamp)
What is going on?
It seems that there is undocumented time window(time limits) for departure date. For example, google direction service can search only routes with in 8 hours after departure_time(we need to clear up this window from google developers team) . So solution will be to add 8 hours to departure_time and try for results, and make loop during suitable time. I tested, that works. I think that is the secret of maps.google.com