Access Google's Traffic Data through a Web Service
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.
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.
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