Calculate a Route
Use the following URL templates to get a walking, driving or transit route by specifying a series of waypoints. A waypoint is a specified geographical location defined by longitude and latitude that is used for navigational purposes. The route includes information such as route instructions, travel duration, travel distance or transit information. You can also request a set of route points.
See Calculate a Truck Route documentation for information on making truck based routing requests.
To overlay a route on a static map by using the Imagery API, see Get a Static Map.
These templates support both HTTP and HTTPS protocols. To use this API, you must have a Getting a Bing Maps Key.
You can specify up to 25 waypoints for a route. Each set of waypoints creates a separate route leg. Between any two (2) waypoints, you can have up to 10 intermediate viaWayPoints. ViaWaypoints define the route path and do not create route legs.
Find a driving route.
Find a walking, driving or transit route by specifying the mode of travel.
For a list of transit agencies, see Bing Maps Transit Coverage. You can request up to three (3) driving or transit route options between two waypoints by using the maxSolutions parameter.
See the Common Parameters and Types section for additional common parameters to use with these URLs.
Common parameters include:
- Output Parameters: Includes response output types and the JSON callback parameters.
- Culture Parameter: Includes a list of the supported cultures.
- User Context Parameters: Includes parameters that set user location and viewport values to help determine locations. For example, these values may help prioritize a set of possible locations when you specify a partial address for a waypoint.
When an alias is provided, you can use the alias to shorten the length of the query parameter. For example, waypoint.1=47.610,-122.107 can be shortened to wp.1=47.610,-122.107.
Parameter values are not case-sensitive.
||waypoint.n: Required. Specifies two or more locations that define the route and that are in sequential order.
viaWaypoint.n: Optional Specifies one or more locations that define intermediate points of a route between waypoints.
|A route is defined by a set of waypoints and viaWaypoints (intermediate locations that the route must pass through). The index (n value) for the set of waypoints and viaWaypoints is an integer starting with 0 or 1. The waypoint and viaWaypoint index values must be sequential and must always increment by 1.
Both waypoint and viaWaypoint locations can be specified as a Point, a landmark, or an address. For more information about Point values, see Location and Area Types.
You can have a maximum of 25 waypoints, and a maximum of 10 viaWaypoints between each set of waypoints. The start and end points of the route cannot be viaWaypoints.
For transit routes and when more than one route is requested (maxSolutions > 1), you must specify only two waypoints, and viaWaypoints are not supported.
Incorrect set of waypoints.
The following set of values is not valid because there is no waypoint.2.
The following set of values is not valid because a viaWaypoint is specified as the starting waypoint.
avoid||**Optional.**Specifies the road types to minimize or avoid when a route is created for the driving travel mode.|A comma-separated list of values from the following list that limit the use of highways and toll roads in the route. In the definitions below, "highway" also refers to a "limited-access highway".
If no values are specified, highways and tolls are allowed in the route.
highways: Avoids the use of highways in the route.
tolls: Avoids the use of toll roads in the route.
ferry: Avoids the use of ferries in the route.
minimizeHighways: Minimizes (tries to avoid) the use of highways in the route.
minimizeTolls: Minimizes (tries to avoid) the use of toll roads in the route. Note: If you specify more than one option for a road type, then the most restrictive option is used. For example, if you set the avoid parameter to both highways and minimizeHighways, the highways option is used and all highways are avoided.
borderCrossing: Avoids crossing country borders in the route.
dbft|Optional. Specifies the distance before the first turn is allowed in the route. This option only applies to the driving travel mode.|An integer distance specified in meters. Use this parameter to make sure that the moving vehicle has enough distance to make the first turn.
hd|Optional. Specifies the initial heading for the route.|An integer value between 0 and 359 that represents degrees from north where north is 0 degrees and the heading is specified clockwise from north. For example, setting the heading of 270 degrees creates a route that initially heads west.
optmz|Optional. Specifies what parameters to use to optimize the route.|One of the following values:
distance: The route is calculated to minimize the distance. Traffic information is not used.
time [default]: The route is calculated to minimize the time. Traffic information is not used.
timeWithTraffic: The route is calculated to minimize the time and uses current traffic information.
timeAvoidClosure: The route is calculated to minimize the time and avoid road closures. Traffic information is not used in the calculation.
optWp|Optional. Instructs the API to rearrange the route waypoints and reduce the route cost specified with the optimize parameter. The route first waypoint wp.0 and last waypoint wp.n order is not changed, their position is considered fixed.|One of the following values:
Note: The parameter is available only for Driving travel mode. The parameter is available only when the route waypoints number is greater than 2, the route is composed of more than just the start and end waypoints.| |
ra|Optional. Specify to include or exclude parts of the routes response.|One or more of the following values:
excludeItinerary: Do not include detailed directions in the response. Detailed directions are provided as itinerary items and contain details such as written instructions and traffic location codes.
routePath: Include a set of point (latitude and longitude) values that describe the route’s path in the response.
transitStops: Include information about transit stops for transit routes.
routeSummariesOnly: Include only travel time and distance for the route, and do not provide other information. Only supported for 2 waypoint routes.
all: Used to specify the following attributes as a group:
Note: When you set the routeAttributes parameter, the
routePathOutput parameter is ignored.
rpo|Optional. Specifies whether the response should include information about
Point (latitude and longitude) values for the route’s path.|Note: This is a legacy parameter. The current recommended way to get route points is to use the routeAttributes parameter.
One of the following values:
Points: A list of Point values for the route’s path is provided in the response.
None [default]: No information about the route’s path is provided in the response.
Note: The current recommended way to get route points is to use routeAttributes parameter.
- The parameter setting
routeAttributes=routePath returns the same values as
- If the
routeAttributes parameter is included in the request with any value (not only
routePathOutput parameter is ignored.|
tl|Optional. Specifies a series of tolerance values. Each value produces a subset of points that approximates the route that is described by the full set of points.
This parameter is only valid when the
routePathOutput parameter is set to
Points.|A set of comma-separated double values. Each value specifies a tolerance that is used to reduce the number of points needed to display a route on a map and still maintain the route shape. If a point is removed and the new route still falls within the specified tolerance of the old route, then the point is not included in the subset of points returned for that tolerance.
You may find it useful to define tolerances for different zoom levels, screen resolutions or other display parameters.
You can specify a maximum of seven (7) tolerance values.
The tolerance is specified in degrees. A degree of latitude is approximately 60 nautical miles, 111 kilometers or 69 statute miles. Therefore, a tolerance value of 0.00001 represents a distance of about one (1) meter in the north-south direction. The distance represented by a degree of longitude varies with latitude. For example at 45 degrees of longitude, a degree of latitude is 111.132 km and a degree of longitude is 78.847 km. At the equator, these values are almost equal with latitude at 100.754 km and longitude at 111.320 km. As you approach the poles, the distance associated with a degree of latitude decreases, and fewer points will be excluded for the same tolerance value. For more information about how longitude distances change with latitude, see Longitude (Wikipedia).
The following diagram illustrates how a tolerance value is used.
du|Optional. The units to use for distance in the response.|One of the following values:
dt|Required when the travel mode is Transit. The dateTime parameter identifies the desired transit time, such as arrival time or departure time. The transit time type is specified by the timeType parameter.
Optional for Driving. When specified and the route is optimized for
timeWithTraffic, predictive traffic data is used to calculate the best route for the specified date time.|A string that contains the date and time formatted as a DateTime value. For information about the string representation options for DateTime values, see DateTime.Parse Method (String).
dateTime=05:42:00 [assumes the current day]
dateTime=03/01/2011 [assumes the current time]|
tt|Required when the travel mode is Transit Specifies how to interpret the date and transit time value that is specified by the
dateTime parameter.|One of the following values:
Arrival: The dateTime parameter contains the desired arrival time for a transit request.
Departure: The dateTime parameter contains the desired departure time for a transit request.
LastAvailable: The dateTime parameter contains the latest departure time available for a transit request.|
maxSolns|Optional. Specifies the maximum number of transit or driving routes to return.|A string that contains an integer value between 1 and 3. The default value is 1.
maxSolns=3 Note: This parameter is available for the
Transit travel modes for routes between two waypoints. This parameter does not support routes with more than two waypoints. For driving routes, you must not set the
distanceBeforeFirstTurn parameters. The
maxSolutions parameter is supported for routes in the United States, Canada, Mexico, United Kingdom, Australia, and India.|
travelMode||Optional. The mode of travel for the route.|One of the following values:
A Route resource is returned when you make a request with one of the following URLs. For more information about the Route resource, see Route Data. For more information about the common response syntax for the Bing Maps REST Services, see Common Response Description. JSON and XML responses are provided for the URL examples in the following section.
These URLs support JSON (application/json) and XML (application/xml) response formats. A JSON response is provided by default, unless you request XML output by setting the output (o) parameter. For more information, see Output Parameters.
Find a driving route.
The following example shows how to request a driving route between two locations that minimizes the use of toll roads. To view the complete XML and JSON responses, see Driving Route Example.
Find a driving route that includes an intermediate route point (viaWaypoint).
The following example shows how to request a driving route between two locations that includes an intermediate viaWaypoint. ViaWaypoints are used to direct a route through specific locations and do not create a new route leg like waypoints.
Find a walking route that minimizes distance.
This example returns a walking route from the Eiffel Tower to the Louvre Museum in Paris, France. The route is optimized for distance and returns the results in XML. To view the complete XML and JSON responses, see Walking Route Example.
Find a transit route.
The following example shows how to request a transit route between the Golden Gate Bridge and Fisherman’s Wharf in San Francisco for 3 PM on the current day. To view the complete XML and JSON responses, see Transit Route Example.
Find up to three driving route options between New York, NY and Philadelphia, PA.
The following example requests up to three (3) driving route options between New York, New York and Philadelphia, Pennsylvania.
Find up to three driving route options between New York, NY and Philadelphia, PA.
The following example requests up to three (3) driving route options between New York, New York and Philadelphia, Pennsylvania and exclude detailed instructions for alternate routes.
Two ways to specify waypoints for a driving route: Point (latitude and longitude coordinates) and location names.
The following two examples show how to request a route between San Francisco and San Diego by using latitude and longitude coordinates and by using location names.
Find a driving route between Redmond, Washington and Seattle, Washington that specifies an initial heading of 90 degrees (east) and that requests the results uses miles as the distance unit.
Find a walking route between two addresses.
This example shows how to request a walking route between two addresses.
Find a driving route that minimizes the distance and specifies that the first turn must be at least 500 meters from the starting point.
The following example optimizes a route between two locations for distance. The first turn on the route must be 500 meters or more from the starting point.
Find a driving route that minimizes travel time based on current traffic conditions.
The following example optimizes a route between two locations and takes the current traffic conditions into account.
Find a driving route that does not use highways or toll roads.
The following example returns a driving route between the cities of Buffalo and Syracuse in New York State. The avoid parameter specifies to not use toll roads or highways. Therefore, the returned route does not use the interstate highway I-90 which would otherwise be part of the route.
Find a driving route and request a set of points that define the route.
This example returns a driving route from the Minneapolis, Minnesota to St. Paul, Minnesota. The route is optimized for distance and requests point values for the route’s path. The results are returned in JSON. To view the complete XML and JSON responses, see Driving Route with Route Path Example.
Find a driving route and exclude the detailed directions (itinerary items).
This example returns a driving route from the Minneapolis, Minnesota to St. Paul, Minnesota, and excludes the detailed itinerary items from the response.
Find a driving route and request a route path and a subset of route path points based on tolerance values.
This example returns a driving route from the Minneapolis, Minnesota to St. Paul, Minnesota. The route is optimized for distance and requests point values for the route’s path. In addition to the full set of route points, a list of tolerances is specified. For each tolerance value, a subset of points is returned in the response. The route defined by each subset of points approximates the route defined by all the points. The difference allowed between the two routes is defined by the tolerance value. To view examples of these subsets of points in the response, see Driving Route using Tolerances Example.
HTTP Status Codes
For more details about these HTTP status codes, see Status Codes and Error Handling.
When the request is successful, the following HTTP status code is returned.
When the request is not successful, the response returns one of the following errors.