Is there a way I can access traffic data that Google provides through a web service?
There seems to be a GTrafficOverlay that puts traffic on top of a route on an embedded google map, but no direct web service that I can consume to, say, give the source and the destination and find the traffic between them?
Is there any other source I can get this data from?
UPDATE (May 2022): From #AbdullahTahan:
Now google has this feature but it's paid and costs 0.01$ per request check this https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#distance-matrix-advanced
UPDATE (March 2016): A lot has happened since this answer was written in 2011, but the core points appear to hold up: You won't find raw traffic data in free API services (at least not for the U.S., and probably not most other places). But if you don't mind paying a bit and/or if you just need things like "travel time for a specific route taking traffic into consideration" you have options. #Anto's answer, for example, points to Google's Maps For Work as a paid API service that allows you to get travel times taking traffic into consideration.
ORIGINAL ANSWER: There is no way (or at least no reasonably easy and convenient way) to get the raw traffic data from Google Maps Javascript API v3. Even if you could do it, doing so is likely to violate some clause in the Terms Of Service for Google Maps. You would have to get this information from another service. I doubt there is a free service that provides this information at the current time, but I would love it if someone proved me wrong on that.
As #crdzoba points out, Bing Maps API exposes some traffic data. Perhaps that can fill your needs. It's not clear from the documentation how much traffic data that exposes as it's only data about "incidents". Slow traffic due to construction would be in there, but it's not obvious to me whether slow traffic due simply to volume would be.
Apparently the information is available using the Google Directions API in its professional edition Maps for work. According to the API's documentation:
Note: Maps for Work users must include client and signature parameters with their requests instead of a key.
[...]
duration_in_traffic indicates the total duration of this leg, taking into account current traffic conditions. The duration in traffic will only be returned if all of the following are true:
The directions request includes a departure_time parameter set to a value within a few minutes of the current time.
The request includes a valid Google Maps API for Work client and signature parameter.
Traffic conditions are available for the requested route.
The directions request does not include stopover waypoints.
You might want to take a look at HERE MAP SERVICE. They have direct traffic data you can use, which is exactly what you need: https://developer.here.com/api-explorer/rest/traffic/traffic-flow-bounding-box
For example, by querying an area of interest, you might get something like this:
{
"RWS": [
{
"RW": [
{
"FIS": [
{
"FI": [
{
"TMC": {
"PC": 32483,
"DE": "SOHO",
"QD": "+",
"LE": 0.71682
},
"CF": [
{
"TY": "TR",
"SP": 9.1,
"SU": 9.1,
"FF": 17,
"JF": 3.2911,
"CN": 0.9
}
]
}
]
}
],
....
This example shows a current average speed SU of 9.1, where the free flow speed FF would be 17. The Jam factor JF is 3.3, which is still considered free flow but getting sluggish.
The units used (miles/km) can be defined in the API call.
To avoid dealing with TMC locations, you can ask for geocoordinates of the road segments by adding responseattributes=sh in the request.
The abbreviations used can be found here Interpreting HERE Maps real-time traffic tags:
"RWS" - A list of Roadway (RW) items
"RW" = This is the composite item for flow across an entire roadway. A roadway item will be present for each roadway with
traffic flow information available
"FIS" = A list of Flow Item (FI) elements
"FI" = A single flow item
"TMC" = An ordered collection of TMC locations
"PC" = Point TMC Location Code
"DE" = Text description of the road
"QD" = Queuing direction. '+' or '-'. Note this is the opposite of the travel direction in the fully qualified ID, For example for
location 107+03021 the QD would be '-'
"LE" = Length of the stretch of road. The units are defined in the file header
"CF" = Current Flow. This element contains details about speed and Jam Factor information for the given flow item.
"CN" = Confidence, an indication of how the speed was determined. -1.0 road closed. 1.0=100% 0.7-100% Historical Usually
a value between .7 and 1.0 "FF" = The free flow speed on this
stretch of road.
"JF" = The number between 0.0 and 10.0 indicating the expected quality of travel. When there is a road closure, the Jam Factor
will be 10. As the number approaches 10.0 the quality of travel is
getting worse. -1.0 indicates that a Jam Factor could not be
calculated
"SP" = Speed (based on UNITS) capped by speed limit
"SU" = Speed (based on UNITS) not capped by speed limit
"TY" = Type information for the given Location Referencing container. This may be freely defined string
Also the source comes from
https://developer.here.com/rest-apis/documentation/traffic/topics/additional-parameters.html
Bing Maps API has a REST service that returns traffic info
http://msdn.microsoft.com/en-us/library/hh441725
Rather than trying to pull the raw traffic data, you can try a different approach.
The Google Directions API allows you to query the api with a particular route and returns a JSON string or XML element as a result.
This result includes the element - ' duration_in_traffic '
This indicates the total duration of the particular leg of the journey, taking into account current traffic conditions. (for information on 'leg' and other elements of the JSON string returned by the Directions API refer link below)
https://developers.google.com/maps/documentation/directions/#JSON
I haven't tried this myself but just something I came across in the documentation.
In India we are using http://www.itrafficnews.com. But the data is posted by the users. I dont think google will provide the data.
Maybe you should have a look at Mapquests Traffic API: http://www.mapquestapi.com/traffic/
The webservice is unfortunately only available for some citys in the US, I think. But probably it solves your problem.
I don't think Google will provide this API. And traffic data not only contains the incident data.
Today many online maps show city traffic, but they have not provide the API for the developer. We even don't know where they get the traffic data. Maybe the government has the data.
So I think you could think about it from another direction. For example, there are many social network website out there. Everybody could post the traffic information on the website. We can collection these information to get the traffic status. Or maybe we can create a this type website.
But that type traffic data (talked about above) is not accurate. Even the information provided by human will be wrong.
Luckily I found that my city now provides an Mobile App called "Real-time Bus Information". It could tell the citizen where the bus is now, and when will arrive at the bus station. And I sniff the REST API in this App.
The data from REST API give the important data, for example the lat and lon, and also the bus speed. And it's real-time data! So I think we could compute the traffic status from these data (by some programming).
Here is some sample data : https://github.com/sp-chenyang/bus/blob/master/sample_data/bjgj_aibang_com_8899_bjgj_php_city_linename_stationno_datatype_type.json
Even the bus data will not enough to compute the accurate real-time traffic status. Incidents, traffic light and other things will affect the traffic status. But I think this is the beginning.
At the end, I think you could try to find whether your city provides these data.
PS: I am always thinking that life will be better for people in the future , but not now.
It is possible to get traffic data.
Below is my implementation in python. The API has some quota & is not fully free, but good enough for small projects
import requests
import time
import json
while True:
url = "https://maps.googleapis.com/maps/api/distancematrix/json"
querystring = {"units":"metric","departure_time":str(int(time.time())),"traffic_model":"best_guess","origins":"ITPL,Bangalore","destinations":"Tin Factory,Bangalore","key":"GetYourKeyHere"}
headers = {
'cache-control': "no-cache",
'postman-token': "something"
}
response = requests.request("GET", url, headers=headers, params=querystring)
d = json.loads(response.text)
print("On", time.strftime("%I:%M:%S"),"time duration is",d['rows'][0]['elements'][0]['duration']['text'], " & traffic time is ",d['rows'][0]['elements'][0]['duration_in_traffic']['text'])
time.sleep(1800)
print(response.text)
Response is :-
{
"destination_addresses": [
"Tin Factory, Swamy Vivekananda Rd, Krishna Reddy Industrial Estate, Dooravani Nagar, Bengaluru, Karnataka 560016, India"
],
"origin_addresses": [
"Whitefield Main Rd, Pattandur Agrahara, Whitefield, Bengaluru, Karnataka 560066, India"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "10.5 km",
"value": 10505
},
"duration": {
"text": "35 mins",
"value": 2120
},
"duration_in_traffic": {
"text": "45 mins",
"value": 2713
},
"status": "OK"
}
]
}
],
"status": "OK"
}
You need to pass "departure_time":str(int(time.time())) is a required query string parameter for traffic information.
Your traffic information would be present in duration_in_traffic.
Refer this documentation for more info.
https://developers.google.com/maps/documentation/distance-matrix/intro#traffic-model
There is a project called Open Traffic which is not fully functional right now but seems to be the right answer in the future.
OpenTraffic is a global data platform to process anonymous positions of vehicles and smartphones into real-time and historical traffic statistics. We're building this in the open, using fully open-source software, with involvement from a growing list of partners.
Related
I'm using the Here API to calculate routes for trucks with 40t. Using the HERE devtools, i got the same error of my APP. The answer is "The API can't calculate the route because of illegal access". I checked the map (image attached) and in the street where my journey will start, with a difference of some meters, it exists two limitations 12t and 18t. The street is one way... If you see the satellite image exists several trucks... The company is testing the software says the trucks goes their...
Can some help me on this?
https://fleet.api.here.com/2/calculateroute.json?waypoint0=41.325299,2.141551&waypoint1=stopOver,3600!41.3291843,2.0317197&waypoint2=stopOver,3600!40.91260530,-8.42291420&waypoint3=38.855951,-9.104382&mode=fastest;truck;traffic:enabled&departure=2020-08-19T02:57:58&alternatives=0&weightPerAxle=14t&limitedWeight=40t&height=4m&width=2.55m&length=16.5m&trailersCount=
If you want to ignore the restrictions for trucks in the route, add the parameter truckRestrictionPenalty and set the value to soft.
The route violating truck restrictions is indicated in the response with dedicated route and manoeuvre notes. The route with the note of the type violation and the text truckRestriction may be travelled at your own responsibility. While driving on such a route, extra care has to be taken as it may result in a vehicle or road infrastructure damage.
You can read more about the parameter here.
Thanks for your feedback, but we are using the Fleet Telematics Api not the Routing API. Using your info, We researched a litle more and we found the equivalent parameter: ignoreWaypointVehicleRestriction.
We added these params &ignoreWaypointVehicleRestriction=5000;0;all and the API returned the route with the warning.
Thanks,
I am using a HERE API call to request traffic incident data from a particular start time. Whenever I include the "type" key and specify "Accident" as the value, no response is returned. However, switching the value to "Construction" does provide a response.
Does anyone have information on how to make the API call return accident data specifically?
Here is the exact call I am using:
https://traffic.api.here.com/traffic/6.3/incidents.json?app_id={{app_id}}&app_code={{app_code}}&startTime=2017-01-01T00:00:00-05:00&type=Accident&bbox=52.5233,13.4035;52.5181,13.4159
There is no data returned as there are no “Accident” type incidents in that location. This can be seen when skipping the “type” parameter:
https://traffic.api.here.com/traffic/6.3/incidents.xml?app_id=APP_ID&app_code=APP_CODE&startTime=2017-01-01T00:00:00-05:00&bbox=52.5233,13.4035;52.5181,13.4159
Traffic Data is dynamic data. Accident can be located somewhere and disappear in a matter of minutes. We recommend to use wego.here.com to locate an accident, or Bing maps (they are all using our services and traffic data).
We were able to find one in Germany right now (should be there until 13:34 German time):
https://traffic.api.here.com/traffic/6.3/incidents.xml?app_id=app_id&app_code=app_code&startTime=2017-01-01T00:00:00-05:00&prox=51.52427,11.85887,15&type=Accident
Hope this helps! Happy Coding!
We are trying to build a alexa skill for our office building so that an echo dot is deployed at the entrance of each floor and help people identify the directions of washrooms and conference rooms and many other. We were sucessful in implementing it.
I would like know how can we utilize same service for multiple floors how can i know in alexa skill set from which echo dot my skill set is being called.
lets say if user ask for washroom directions. Alexa needs to identify he is in first floor and tell him to take left. if he is in second floor it needs to tell him take right.
Regards
Kalyan
So far Alexa cannot identify the exact location. The only location it can find is the address linked with the account. I can think of 2 solutions.
Solution 1:- If the user asks for direction then your Alexa skill can ask a question back to the user that which floor they are in.
Solution 2:- You can create multiple skill sets for each echo in each floor. Say the echo in the first floor can provide directions for first floor and so on.
I would prefer Solution 1 as creating separately skill for each floor may not be a good idea. But if you don't want the user to input which floor they are in they go for solution 2.
If devices aren't going to move (ever or often), I would look at the Device ID.
Amazon recently added the Device ID (unique across all devices) to the LaunchRequest JSON payload.
{
"session": {
"new": true,
"sessionId": "string",
"application": {
"applicationId": "string"
},
},
"context": {
"device": {
"deviceId": "string",
},
"request": {}
}
I would have one Skill that looks at the requesting device ID (context.device.deviceId) and delivers the correct answer based on the context.
Obviously, you'd need to manage a mapping between floor and device ID, and update that if the device ever moves.
I had asked this question about a year ago during an Office Hours session with Amazon. I was told that their intention was to prevent Alexa from knowing much if anything about the device it was running on.
Since then Amazon has added limited capability to allow Alexa skills to know about the particular user and their device. It may be possible to map specific devices within a skill, but that sounds a bit tricky and fragile.
A more robust approach would be Vijayanath's solution 2 above. I believe this would also require that each Echo be on a separate account, though. I'm not aware of any way to deploy a skill to a specific device and not all the others.
I used this approach for a halloween costume last year to allow 2 dots sitting on my shoulders to respond differently to the same utterances (think of the scene from Animal House). With just 2 devices, this worked ok. Depending on how many devices you intend to have, this might be prohibitively cumbersome.
I want to know if there is any api that can allow me to get the number of reviews from an url.
I know that google offers the possibility to get this number by using the placeid, but the only information I have is the url of the website of a company.
Any ideas please?
Maybe, but probably not.
Places API Text Search seems to be able to find places by their URL:
https://maps.googleapis.com/maps/api/place/textsearch/json?key=YOURKEY&query=http://www.starbucks.com/store/1014527/us/303-congress-street/303-congress-street-boston-ma-02210
However, this is not a documented feature of the API and I do not think this can be relied upon, so I'd recommend filing a feature request, to make this a supported, reliable feature.
As for the amount of reviews, you may be interested in:
Issue 3484: Add # of reviews to the Place Details Results
I've written an API like this for Reviewsmaker, but I target specific business names not URLs. See this example (I activated a key for this purpose for now):
http://reviewsmaker.com/api/google/?business=life%20made%20a%20little%20easier&api_key=4a2819f3-2874-4eee-9c46-baa7fa17971c
Or, try yourself with any business name:
http://reviewsmaker.com/api/google/?business=Toys R Us&api_key=4a2819f3-2874-4eee-9c46-baa7fa17971c
The following call would return a JSON object which shows:
{
"results":{
"business_name":"Life Made A Little Easier",
"business_address":"1702 Sheepshead Bay Rd, Brooklyn, NY 11235, USA",
"place_id":"ChIJ_xjIR2REwokRH2qEigdFCvs",
"review_count":38
},
"api":{
"author":"Ilan Patao",
"home":"www.reviewsmaker.com"
}
}
Pinging this EP using a Chronjob for example once every hour or two and return the review_count can pretty much build your own review monitoring app;
You can probably do what you're looking for if you query the Places API Text Search or the CSE (Custom Search Engine) API to lookup the URL, return back the matching name of the business associated with this URL and calling an endpoint like this one to return back the associated review count.
You can probably code this in py or PHP. Not sure how familiar you are with data parsing, but I was able to build my API based on Google's CSE API. CSE provides metadata in its results which contain the total reviews, so if you create a CSE engine and use the CSE API looking for business schemas, review schemas, etc; you can return back items and within the PageMap node there are objects with data that you need very little tweaking to do (such as string replacing, trimming) which will return back the values you're looking for.
Hope my answer helped, at least to lead you in the right direction :)
I am trying to calculate the toll cost between two points in Australia.
Here is the sample URL i am using at the moment:
http://tce.cit.api.here.com/1/tollcost.json?region=AUS&release=2015Q1&start_ts=now&vspec=3%3B0%3B0%3B2%3B0%3B0%3B5%3B340%3B0%3B7500%3B7500%3B0%3B0%3B0%3B1%3B4%3B1%3B0&route=1353326419097748185%3B1353396779235213606&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg
The response i get back is:
{
"errors": [
"Error id: fc4bc014-a17a-4efb-a346-4fad9d01a0ef",
"A technical error occurred while processing the toll cost. Please contact TCS."
],
"warnings": [
"The combination \"link id,remaining time\" for element number \"1\" is invalid. The automatic datetime filtering will be disabled."
],
"countries": [],
"onError": true
}
Not sure if the issue is my linkId's, region, map release, or something entirely different.
I'm not finding a lot of useful documentation or feedback for this, so some help would be much appreciated :)
edit:
We ended up building our own solution, though it only supports QLD & NSW so far. Might have to licence it out some day ;)
The documentation example have the version which are not supported now, HERE will update its documentation and regrets the inconvenience.
I implemented the map toll API for Australia and had issues too. I created a support ticket and the response was that Australia toll calculations are not covered yet.
The link ID 1353326419097748185 is not a valid link ID.
Please use the link IDs provided in the response of the HERE router.
You don't have to work with link IDs, you can also provide the start/destination coordinates, so that the toll cost service computes the route.
Examples: https://tcs.ext.here.com/examples/v3/route_toll_cost
Search for TCE, the 3rd example computes the route and adds the toll cost.