google maps real time traffic - json

I'm using Google Maps web-services -> Distance Matrix API.
My goal is getting driving time between two or more fixed locations, but considering real-time traffic.
I have tried a couple of parameters combinations, but I always get a static trip duration on the replied JSON.
Do you have a recommendation regarding building a request for getting back tip duration considering real-time traffic?

I have tried the following request on a browser, in order to get a JSON reply:
http://maps.googleapis.com/maps/api/distancematrix/json?&origins=Guadalajara&destinations=Chapala&mode=driving&departure_time=now
However, the parameter "duration" is always the same:
duration
text "54 mins"
I would like to get the trip duration considering real time traffic as part of the replied JSON, like when using Google Maps on web:
https://www.google.com/maps/dir/Guadalajara,+Jal./Chapala,+Jal./#20.4809265,-103.3652921,11z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x8428b18cb52fd39b:0xd63d9302bf865750!2m2!1d-103.3496092!2d20.6596988!1m5!1m1!1s0x842f40b1771f4cb7:0x73c1721b67d87f53!2m2!1d-103.1846016!2d20.3051576!3e0

Related

Google directions api singe source multiple destinations

I have a database with a list of locations and I have to get the route steps, drive distance and drive time for all combinations of locations in the database.
I have the latitude and longitude stored in the database for every location.
I'm using the google directions service api to get the information.
As long as the number of records was low, I could get the results from my code within a minute using threading.
However as the number of records increased, the number of records in combination increased exponentially (trust me, this is not the issue and the number of combinations have the potential to reach 100K), thereby causing an increase in the number of requests to be made to directions api and hence the time taken for retreival.
I understand since a large number of rest connections need to be made to the directions api, network latency plays in and the time taken to retrieve the results increases.
I googled and found that some of the maps api's (for instance waypoints in the directions service api) allow you to specify more than 1 value using the pipe operator ( | ).
I attempted to do the same and retrieve information for one source multiple destinations for every rest request however I get a NOT_FOUND status returned from the directions service.
Could someone please help me figure out how to get routes and the distance and time from the same origin but multiple destinations using the directions api.
Following is a sample url and the response I received (API_KEY was removed on purpose, cannot share that):
https://maps.googleapis.com/maps/api/directions/json?key=API_KEY&origin=49.794150,-84.564514&destination=49.244978,-88.146057|49.173205,-84.756775
{
"geocoded_waypoints" : [
{},
{
"geocoder_status" : "ZERO_RESULTS"
}
],
"routes" : [],
"status" : "NOT_FOUND"
}
Directions API doesn't support multiple origins or destinations. You can specify one origin, one destination and up to 23 waypoints.
https://developers.google.com/maps/documentation/directions/intro#Waypoints
The request with waypoints looks like:
https://maps.googleapis.com/maps/api/directions/json?origin=49.794150%2C-84.564514&destination=49.173205%2C-84.756775&waypoints=49.244978%2C-88.146057&key=YOUR_API_KEY
If you would like to test your routes and see the visual representation, you can use Directions calculator:
https://directionsdebug.firebaseapp.com/?origin=49.794150%2C-84.564514&destination=49.173205%2C-84.756775&waypoints=49.244978%2C-88.146057
Hope it helps!

googleapis is not displaying map randomly some times

We are using API for static maps. Some times map is not displayed with the correct information, Instead it displays a crossed image . This is happening randomly for few seconds.
Ex1: https://maps.googleapis.com/maps/api/staticmap?center=51.4666667,-116.5833333&zoom=11&size=380%20x%20380&sensor=false&markers=51.4666667,-116.5833333
Ex2: https://maps.googleapis.com/maps/api/staticmap?center=51.4355096,-0.405238800000006&zoom=13&size=380%20x%20380&sensor=false&markers=51.4355096,-0.405238800000006
Thanks,
Kris
Most websites and applications may use the Google Static Maps API free of charge. However, if you consistently generate a high amount of traffic, usage limits apply and you will need to pay for extra usage. If your site or application generates 25,000 Static Maps image requests or more each day, for more than 90 consecutive days, Google will attempt to get in touch with you to talk about payment. Don't worry, if you go over the limits, Google won't immediately shut off your API access or display error messages on your site.
It is recommended that you sign up for an API key, so that you can track your usage via the Google APIs Console. Please note also that the following additional limits apply to applications that don't use an API key: 1,000 Static Maps image requests per IP address per 24 hour period, and 50 Static Maps image requests per IP address per minute.

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.

Google geocode api limits

I am utilizing the Google Maps API to obtain driving directions to several locations on one page. There are JQuery selectors on the page where a user can select a different locations and view the driving directions for that location.
I am loading all of the requests on page load and I seem to be hitting a limit when I load more than 10 where it reports the remaining addresses cannot be found. I'm assuming there's a limit of 10 per second or something like that.
Does anybody have any more information about this, and ways to get around it besides subscribing to the premier service?
Thanks!
The Geocoding service is subject to daily limits per ip address (client) and a maximum request rate, which is probably what's causing the issue for you.
Here is a discussion from this morning on the rates of various services:
Geocoding Services - limits - Google vs Yahoo vs others?
But you will probably find this article/sample from Google more helpful (See the timing Geocoding Requests section):
http://code.google.com/apis/maps/articles/phpsqlgeocode.html
Basically the concept is to add a delay between your requests and to increase that delay each time you receive an error message.
Short answer seems to be:
https://developers.google.com/maps/articles/geocodestrat#quota-limits
I have found that the usage limits are different (lower) when using the javascriptV3 api than when using the web services api directly. I have been getting 'over usage limit' errors from the javascript api at rates as low as 1/s after the first 10 requests or so. The javascript api is determining this on the client side, as the only results showing up in the chrome network panel are successful requests. changing my code to use the web services directly for geocoding (and enabling that specific api in the api console) worked great for me.

ASP.NET & Google Maps API Error Code "620"on shared hosting

We have a Map It feature on a Real Estate Website and its on a Shared Host, the feature basically shows you the location of a property of works fine for a few hours a day but it stops working later in the day because of error Code "620" for the map request from Google maps API KEY.
we need this issue fix immediately.
Sample could be found here http://www.luxuryrentalsmiamibeach.com/The-Setai-Miami-Beach-13
click on the Map It link to see example
The "Map It" link works flawlessly ATM. The Google error Code 620 means G_GEO_TOO_MANY_QUERIES which either means you had too many API requests per IP per day or in an unspecified time frame.
About the too many API requests per day you cannot do much besides load balancing, changing your IP or paying for the Google Maps API. About the too many API requests per time frame (e.g. 2000 requests per minute) you can do something by delaying your requests.
Also think about caching your results serverside to not put too much strain on the Google servers.
There are several tutorials available on the 620 error and how to circumvent it, just google for it. To get you started you can read "Geocoding multiple addresses"