Traffic Service Developer's Guide

For documentation on v1 of the Traffic Service, please visit the Traffic Service v1 Developer's Guide.

The Traffic Service provides real time traffic information related to markets, incidents, and flow.

See our Release Notes for details on the latest additions to this service.

The following example demonstrates a simple request to get incidents given a bounding box. The JavaScript code which sends the request and displays the result can be viewed here.

Location:
Input Format: Uses "json=" or "xml=" if appropriate.
Output Format:
Incident Types: Construction & Incidents
Construction
Incidents


Sample URL for incidents on the current map:


Sample URL for flow image of traffic on the current map:



Common Options

The following table describes the request parameters common to all traffic service requests

Request Parameter Description Required?
inFormat
Specifies the format of the request. If this parameter is not supplied, the input format is assumed to be JSON-formatted text. The JSON-formatted input text must be supplied as either the "json" parameter of an HTTP GET, or as the BODY of an HTTP POST. If this parameter is "xml", the XML-formatted input text must be supplied as either the "xml" parameter of an HTTP GET, or as the BODY of an HTTP POST.

Must be one of the following, if supplied:
  • kvp
  • json
  • xml
Defaults to "json" if not supplied
No
callback
A JavaScript function name. The JSON-formatted response will be wrapped in a call to the supplied callback function name to provide JSONP functionality. This functionality might be needed to do cross-site scripting. See the Wikipedia.org entry for JSON for more details.
No
outFormat Specifies the format of the response. Must be one of the following, if supplied:
  • json
  • xml
Defaults to "json" if not supplied
No

Traffic Incidents

The Traffic Incidents request returns a structured list of traffic incidents for a specified bounding box in JSON or XML formats, e.g., road construction, traffic collisions.

Incidents URL Parameters

The following table describes the request parameters that may be included to make an incident request

Request Parameter Description Required?
filters A list of incident types to return. Possible values are:
  • incidents
  • construction
  • event
  • congestion

Default: incidents,construction
No
boundingBox The area in which to search for incidents. Yes

Incidents response

Response Field Description
lat Latitude of the incident.
lng Longitude of the incident.
type Incident type. Values are:
  1. = Construction
  2. = Event
  3. = Congestion/Flow
  4. = Incident/accident
severity The incident severity. Values range from 0-4 with 4 indicating the highest severity.
eventCode The incident event code. These are standard Alert-C event codes.
Visit ALERT-C Codes Project
impacting Indicates if the incident is impacting traffic.
startTime The start time (ISO 8601 Combined Date and Time format) of the incident.
endTime The end time (ISO 8601 Combined Date and Time format) of the incident.
shortDesc A short description of the incident.
fullDesc Full description of the incident.
iconURL URL for an icon to use for displaying the incident.
distance Optional (0 if not sent from traffic provider). The length of the road extent affected by the incident.
delayFromTypical Optional (0 if not sent from traffic provider). The delay (minutes) from typical conditions. This is the increase in travel time across the road extent affected by the incident relative to the travel time under average conditions for the given day of the week and time.
delayFromFreeFlow Optional (0 if not sent from traffic provider). The delay (minutes) from typical conditions. This is the increase in travel time across the road extent affected by the incident relative to the travel time under free-flowing conditions.
tmcs Optional. List of Traffic Message Channel ids located at the incident.
Sample JSON Response Sample XML Response
{
    incidents: [
        {
            fullDesc: "One lane closed due to maintenance work on California Street Eastbound between 18th Street and 19th Street.",
            lng: -104.988591,
            severity: 2,
            shortDesc: "California Street E/B : Lane closed between 18th Street and 19th Street ",
            endTime: "2013-08-02T01:59:00",
            type: 1,
            id: "330627538",
            startTime: "2013-02-04T19:00:00",
            impacting: true,
            tmcs: [ ],
            eventCode: 0,
            iconURL: "http://api.mqcdn.com/mqtraffic/const_mod.png",
            lat: 39.748002
        },
    ...
    ],
    mqURL: "http://www.mapquest.com/maps?traffic=1&latitude=39.7397611&longitude=-104.984793",
    info: {
        copyright: {
            text: "2013 MapQuest, Inc.",
            imageUrl: "http://api.mqcdn.com/res/mqlogo.gif",
            imageAltText: "2013 MapQuest, Inc."
        },
        statuscode: 0,
        messages: [ ]
    }
}  
<IncidentsResponse>
   <Incidents>
      <Incident>
         <id>330627538</id>
         <type>1</type>
         <severity>2</severity>
         <eventCode>0</eventCode>
         <lat>39.748002</lat>
         <lng>-104.988591</lng>
         <startTime>2013-02-04T19:00:00.000-05:00</startTime>
         <endTime>2013-08-02T01:59:00.000-04:00</endTime>
         <shortDesc>California Street E/B : Lane closed between 18th Street and 19th Street </shortDesc>
         <fullDesc>One lane closed due to maintenance work on California Street Eastbound between 18th Street and 19th Street.</fullDesc>
         <iconURL>http://api.mqcdn.com/mqtraffic/const_mod.png</iconURL>
      </Incident>
      ...
   </Incidents>
   <mqURL>http://www.mapquest.com/maps?traffic=1&latitude=39.7397611&longitude=-104.984793</mqURL>
   <info>
      <statusCode>0</statusCode>
      <messages/>
      <copyright>
         <imageUrl>http://api.mqcdn.com/res/mqlogo.gif</imageUrl>
         <imageAltText>2013 MapQuest, Inc.</imageAltText>
         <text>2013 MapQuest, Inc.</text>
      </copyright>
   </info>
</IncidentsResponse>
Note: mqURL contains a link back to mapquest.com that would show all the incidents on a mapquest map.

Traffic Markets

The Traffic Markets Request returns a structured list of regions, or "markets", for which MapQuest provides Traffic data. The list is available in JSON or XML formats.

This function takes no parameters other than a valid key.

Sample Markets request


Sample JSON Response Sample XML Response
{markets: [
  {state: "OH", 
   lng: -81.519202, 
   lat: 41.081401,
   iconURL: "http://...",
   city: "Akron / Canton"
   zoom: 10,
   mqURL: "http://www.mapquest.com...",
   boundingBox: {
     ul: {
       lng: -82.110762
       lat: 41.359286
     },
     lr: {
       lng: -80.926346
       lat: 40.803517
     }
   }
  },
  ...
 ],
 info: {
    copyright: {
    },
    statuscode: 0,
    messages: []
 }
}
<MarketsResponse>
   <markets>
      <market>
         <city>Akron / Canton</city>
         <state>OH</state>
         <lng>-81.519202</lng>
         <lat>41.081401</lat>
         <iconURL>http://...</iconURL>
         <zoom>10</zoom>
         <mqURL>http://www.mapquest.com...</mqURL>
         <boundingBox>
            <ul>
               <latLng>
                  <lat>41.359286</lat>
                  <lng>-82.110762</lng>
               </latLng>
            </ul>
            <lr>
               <latLng>
                  <lat>40.803517</lat>
                  <lng>-80.926346</lng>
               </latLng>
            </lr>
         </boundingBox>
      </market>
      ...   
   </markets>
   <info>
      <statusCode>
         0
      </statusCode>
      <messages/>
   </info>
   <copyright>
      ...
   </copyright>
</MarketsResponse>
Note: mqURL contains a link back to viewing that specific market on mapquest.com


Flow Image

The Flow Request returns an image of the current traffic for a particular area.

The following table describes the request parameters that may be included in a Flow request

  • gif
  • png
Default is "gif"
Request Parameter Description Required?
mapState
A valid mapState for this image.

This parameter must contain the following information:
  • width (pixels)
  • height (pixels)
  • center (lat/lng of map center)
  • scale (map scale)
To describe a mapState object using Key/Value pair input, supply the following query parameters:
  • mapWidth
  • mapHeight
  • mapLat
  • mapLng
  • mapScale
mapLat and mapLng represent the latitude and longitude of the center of the map.


Note: The scale factor / zoom of this mapState must be one of the values in the following table.
ZoomScale
10433343
11216671
12108335
1354167
1427083
1513541
166770
173385
181692
Yes
imageType Specifies the output flow image format. No


Sample Flow Image request

The following sample returns a 400x400 pixel image centered on Arlington, VA, with a scale of 108335 (zoom level of 10)

  © MapQuest, Inc. All rights reserved.    Privacy Policy | Terms of Use