Mobility - Get Transit Route Preview

Important

The Azure Maps Mobility Services Preview has been retired and will no longer be available and supported after October 5, 2021. All other Azure Maps API and Services are unaffected by this retirement announcement. For details, see Azure Maps Mobility Preview Retirement.

Transit Route API

Applies to: S1 pricing tier.

Get Transit Route API will allow trip planning returning the best possible route options between an origin and destination by using multi-modal search. Service provides a variety of travel modes, including walk, bike, and public transit. The API supports parameters to request one or multiple public transit types such as bus, tram and subway, and prefer a specific transit agency operating in the area. Also, service provides transit fare details and options to choose optimal route with least walk or transfers and specify arrival or departure times when user need to be at a specific destination by a certain time.

GET https://atlas.microsoft.com/mobility/transit/route/json?api-version=1.0&origin={origin}&destination={destination}
GET https://atlas.microsoft.com/mobility/transit/route/json?subscription-key={subscription-key}&api-version=1.0&metroId={metroId}&origin={origin}&originType={originType}&destination={destination}&destinationType={destinationType}&modeType={modeType}&transitType={transitType}&agency={agency}&agencyType={agencyType}&time={time}&timeType={timeType}&routeType={routeType}&bikeType={bikeType}&language={language}

URI Parameters

Name In Required Type Description
format
path True

Desired format of the response. Only json format is supported.

api-version
query True
  • string

Version number of Azure Maps API. Current version is 1.0

destination
query True
  • string

The destination of the route. By default the destinationType=position, specified as a comma separated string composed by latitude followed by longitude, e.g. "47.641268,-122.125679”.

origin
query True
  • string

The origin of the route. By default originType=position, specified as a comma separated string composed by latitude followed by longitude, e.g. "47.641268,-122.125679”.

agency
query
  • array

Specifies whether to prefer routes from a specific set of agencies if possible; as a comma separated list. If valid trip isn’t found with the preferred agency, or only one with very long trips or with large number of transfers, itineraries with other agencies will be returned.

agencyType
query

Specifies the agency identifier to request routes from preferred agencies. By default the agencyType=agencyId.

bikeType
query
  • string

Bike type of the bike. Specifies which type of bikes will be used. Only private bikes are supported.

destinationType
query

The type of the destination.

language
query
  • string

Language in which search results will be returned. Only NGT is supported. Please refer to Supported languages for details.

metroId
query
  • integer
int32

The unique id of the metro area. Can be retrieved via Get Metro Area API.

modeType
query
  • array

The mode of travel for the requested route; as comma separated list. If not specified, all modes will be allowed. All modes might not be available in all metro areas. If valid trip is not found, empty result will be returned. Supported values are:

  • walk - Walk (pedestrian)
  • bike - Bike
  • publicTransit - Public transit
originType
query

The type of the origin. By default originType=position, specified as a comma separated string composed by latitude followed by longitude, e.g., "47.641268,-122.125679”.

routeType
query

The type of route requested. If not specified, 'optimal' will be used.

subscription-key
query
  • string

One of the Azure Maps keys provided from an Azure Map Account. Please refer to this article for details on how to manage authentication.

time
query
  • string

The time of departure or arrival in the local time in ISO format (2019-04-05T14:24:18-04:00). If timeType is not specified, it will be assumed to be 'departure' and time is the current local time at the origin point.

timeType
query

Specifies whether the time signifies departure time or arrival time. If not defined, default value is 'departure'.

transitType
query
  • array

Applicable only with modeType = publicTransit. Allow only a specific set of public transit types (as a comma separated list) to be returned for the route. Note that the requested transitType may not be available for the entire route. If not specified, all modes will be allowed. Supported values are:

  • bus - Bus
  • cableCar - Cable car
  • ferry - Ferry
  • funicular - Funicular
  • gondola - Gondola
  • rail - Rail
  • tram - Tram
  • subway - Subway/Metro

Request Header

Name Required Type Description
x-ms-client-id
  • string

Specifies which account is intended for usage in conjunction with the Azure AD security model. It represents a unique ID for the Azure Maps account and can be retrieved from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see the following articles for guidance.

Responses

Name Type Description
200 OK

OK

400 Bad Request

Bad request: one or more parameters were incorrectly specified or are mutually exclusive.

401 Unauthorized

Access denied due to invalid subscription key or invalid Azure Active Directory (Azure AD) bearer token. Make sure to provide a valid key for an active Azure subscription and Maps resource. Otherwise, verify the WWW-Authenticate header for error code and description of the provided Azure AD bearer token.

Headers

  • WWW-Authenticate: string
403 Forbidden

Permission, capacity, or authentication issues.

404 Not Found

Not Found: the requested resource could not be found, but it may be available again in the future.

500 Internal Server Error

An error occurred while processing the request. Please try again later.

Security

azure_auth

These are the Azure Active Directory OAuth2 Flows. When paired with Azure role-based access control it can be used to control access to Azure Maps REST APIs. Azure role-based access controls are used to designate access to one or more Azure Maps resource account or sub-resources. Any user, group, or service principal can be granted access via a built-in role or a custom role composed of one or more permissions to Azure Maps REST APIs.

To implement scenarios, we recommend viewing authentication concepts. In summary, this security definition provides a solution for modeling application(s) via objects capable of access control on specific APIs and scopes.

Notes

  • This security definition requires the use of the x-ms-client-id header to indicate which Azure Maps resource the application is requesting access to. This can be acquired from the Maps management API.

The Authorization URL is specific to the Azure public cloud instance. Sovereign clouds have unique Authorization URLs and Azure Active directory configurations. * The Azure role-based access control is configured from the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs. * Usage of the Azure Maps Web SDK allows for configuration based setup of an application for multiple use cases.

  • Currently, Azure Active Directory v1.0 tokens are supported.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

subscription-key

This is a shared key that is provisioned when creating an Azure Maps resource through the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.

With this key, any application is authorized to access all REST APIs. In other words, these can currently be treated as master keys to the account which they are issued for.

For publicly exposed applications, our recommendation is to use server-to-server access of Azure Maps REST APIs where this key can be securely stored.

Type: apiKey
In: query

Examples

TransitRoute

Sample Request

GET https://atlas.microsoft.com/mobility/transit/route/json?api-version=1.0&origin=41.948437, -87.655334&originType=position&destination=41.878876, -87.635918&destinationType=position&modeType=publicTransit&transitType=bus

Sample Response

{
  "results": [
    {
      "itineraryId": "41372ab5-8577-481a-ab24-e84572fe69a5---2020092910DC67FA27034F15A29F4AE5415ADAF2:0---81",
      "departureTime": "2020-09-30T00:30:29Z",
      "arrivalTime": "2020-09-30T01:18:16Z",
      "travelTimeInSeconds": 2867,
      "numberOfLegs": 4,
      "legs": [
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T00:30:29Z",
          "legEndTime": "2020-09-30T00:34:01Z",
          "caption": "North Clark Street",
          "lengthInMeters": 196
        },
        {
          "legType": "Wait",
          "legStartTime": "2020-09-30T00:34:01Z",
          "legEndTime": "2020-09-30T00:35:02Z",
          "caption": "22"
        },
        {
          "legType": "Bus",
          "legStartTime": "2020-09-30T00:35:02Z",
          "legEndTime": "2020-09-30T01:12:52Z",
          "caption": "22",
          "lengthInMeters": 8463,
          "legFare": {
            "fares": [
              {
                "price": {
                  "amount": 225,
                  "currencyCode": "USD"
                },
                "usage": "pay"
              }
            ]
          }
        },
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T01:12:53Z",
          "legEndTime": "2020-09-30T01:18:16Z",
          "lengthInMeters": 421
        }
      ],
      "itineraryFare": {
        "price": {
          "amount": 225,
          "currencyCode": "USD"
        },
        "tickets": [
          {
            "amount": 225,
            "currencyCode": "USD"
          }
        ]
      }
    },
    {
      "itineraryId": "41372ab5-8577-481a-ab24-e84572fe69a5---2020092910DC67FA27034F15A29F4AE5415ADAF2:1---81",
      "departureTime": "2020-09-30T00:32:42Z",
      "arrivalTime": "2020-09-30T01:26:29Z",
      "travelTimeInSeconds": 3227,
      "numberOfLegs": 3,
      "legs": [
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T00:32:42Z",
          "legEndTime": "2020-09-30T00:39:40Z",
          "caption": "West Sheridan Road",
          "lengthInMeters": 480
        },
        {
          "legType": "Wait",
          "legStartTime": "2020-09-30T00:39:40Z",
          "legEndTime": "2020-09-30T00:40:41Z",
          "caption": "151"
        },
        {
          "legType": "Bus",
          "legStartTime": "2020-09-30T00:40:41Z",
          "legEndTime": "2020-09-30T01:26:29Z",
          "caption": "151",
          "lengthInMeters": 10539,
          "legFare": {
            "fares": [
              {
                "price": {
                  "amount": 225,
                  "currencyCode": "USD"
                },
                "usage": "pay"
              }
            ]
          }
        }
      ],
      "itineraryFare": {
        "price": {
          "amount": 225,
          "currencyCode": "USD"
        },
        "tickets": [
          {
            "amount": 225,
            "currencyCode": "USD"
          }
        ]
      }
    },
    {
      "itineraryId": "41372ab5-8577-481a-ab24-e84572fe69a5---2020092910DC67FA27034F15A29F4AE5415ADAF2:2---81",
      "departureTime": "2020-09-30T00:28:04Z",
      "arrivalTime": "2020-09-30T01:24:46Z",
      "travelTimeInSeconds": 3402,
      "numberOfLegs": 7,
      "legs": [
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T00:28:04Z",
          "legEndTime": "2020-09-30T00:35:40Z",
          "caption": "West Waveland Avenue",
          "lengthInMeters": 522
        },
        {
          "legType": "Wait",
          "legStartTime": "2020-09-30T00:35:40Z",
          "legEndTime": "2020-09-30T00:36:41Z",
          "caption": "8"
        },
        {
          "legType": "Bus",
          "legStartTime": "2020-09-30T00:36:41Z",
          "legEndTime": "2020-09-30T01:09:41Z",
          "caption": "8",
          "lengthInMeters": 8059,
          "legFare": {
            "fares": [
              {
                "price": {
                  "amount": 225,
                  "currencyCode": "USD"
                },
                "usage": "pay"
              }
            ]
          }
        },
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T01:09:42Z",
          "legEndTime": "2020-09-30T01:11:59Z",
          "caption": "West Van Buren Street",
          "lengthInMeters": 174
        },
        {
          "legType": "Wait",
          "legStartTime": "2020-09-30T01:11:59Z",
          "legEndTime": "2020-09-30T01:18:43Z",
          "caption": "126"
        },
        {
          "legType": "Bus",
          "legStartTime": "2020-09-30T01:18:43Z",
          "legEndTime": "2020-09-30T01:22:45Z",
          "caption": "126",
          "lengthInMeters": 1092,
          "legFare": {
            "fares": [
              {
                "price": {
                  "amount": 25,
                  "currencyCode": "USD"
                },
                "usage": "pay"
              }
            ]
          }
        },
        {
          "legType": "Walk",
          "legStartTime": "2020-09-30T01:22:46Z",
          "legEndTime": "2020-09-30T01:24:46Z",
          "lengthInMeters": 102
        }
      ],
      "itineraryFare": {
        "price": {
          "amount": 250,
          "currencyCode": "USD"
        },
        "tickets": [
          {
            "amount": 225,
            "currencyCode": "USD"
          },
          {
            "amount": 25,
            "currencyCode": "USD"
          }
        ]
      }
    }
  ]
}
{
  "error": {
    "code": "400 BadRequest",
    "message": "Bad request: one or more parameters were incorrectly specified or are mutually exclusive."
  }
}
{
  "error": {
    "code": "401 Unauthorized",
    "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
  }
}
{
  "error": {
    "code": "403 Forbidden",
    "message": "Permission, capacity, or authentication issues."
  }
}
{
  "error": {
    "code": "404 NotFound",
    "message": "Not Found: the requested resource could not be found, but it may be available again in the future."
  }
}
{
  "error": {
    "code": "500 InternalServerError",
    "message": "An error occurred while processing the request. Please try again later."
  }
}

Definitions

AgencyType

Specifies the agency identifier to request routes from preferred agencies. By default the agencyType=agencyId.

DestinationType

The type of the destination.

Fares

Detailed fare information for the leg.

ItineraryFare

Itinerary level transit fare information.

ItineraryResult
JsonFormat

Desired format of the response. Only json format is supported.

LegFare

Leg level public transit fare information. Returned only if fare information is available for the entire itinerary level and supported by the local transit agency.

LegType
ODataError

This object is returned when an error occurs in the Azure Maps API.

ODataErrorResponse

This response object is returned when an error occurs in the Azure Maps API.

OriginType

The type of the origin. By default originType=position, specified as a comma separated string composed by latitude followed by longitude, e.g., "47.641268,-122.125679”.

Price
RouteItineraryLeg
Tickets

An array describing the individual prices of each of the tickets that the user is expected to purchase throughout this itinerary. The list isn’t ordered.

TimeType

Specifies whether the time signifies departure time or arrival time. If not defined, default value is 'departure'.

TransitRouteResponse

This object is returned from a successful Get Transit Stop Info call

TransitRouteType

The type of route requested. If not specified, 'optimal' will be used.

AgencyType

Specifies the agency identifier to request routes from preferred agencies. By default the agencyType=agencyId.

Name Type Description
agencyId
  • string

The Id of the transit agency, e.g. '5872'

agencyKey
  • string

The agency’s GTFS Id.
Note: When this value is used, the metroId parameter is required.

agencyName
  • string

The name of the transit agency, e.g. Metro Transit.

DestinationType

The type of the destination.

Name Type Description
position
  • string

The destination of the route as a comma separated string composed by latitude followed by longitude e.g. "47.641268,-122.125679".

stopId
  • string

The unique Azure Maps identifier for the respective public transit stop. When referring to public transit stops over time, it is recommended to use stopId since it will not change, as long as the physical stop exists.

stopKey
  • string

The GTFS stop Id. GTFS stop Ids are provided by the transit authority and are subject to change.
Note: When this value is used, the metroId parameter is required.

Fares

Detailed fare information for the leg.

Name Type Description
price

The price of the ticket when purchased for the individual leg, not for the entire route at once.

usage
  • string

Supported values are:

  • pay – user is expected to pay for this ticket in order to consume the current leg
  • transfer – user can use a ticket purchased in a previous leg in order to consume the current leg. In general, when transfer is specified, the number of transfers is counted, and has a limit.
  • continue – user can use a ticket purchased in a previous leg in order to consume the current leg. In general, when continue is specified, the number of transfers isn’t incremented for this leg.
  • upgrade – user is expected to upgrade a ticket purchased in a previous leg in order to consume the current leg.

ItineraryFare

Itinerary level transit fare information.

Name Type Description
price

The total price for all tickets a user is expected to purchase in order to complete this itinerary.

tickets

An array describing the individual prices of each of the tickets that the user is expected to purchase throughout this itinerary. The list isn’t ordered.

ItineraryResult

Name Type Description
arrivalTime
  • string

The date and time of arrival at the destination point in ISO 8601 format, e.g. 1996-12-19T19:39:57-08:00.

departureTime
  • string

The date and time of departure from the origin point in ISO 8601 format, e.g. 1996-12-19T16:39:57-08:00.

itineraryFare

Itinerary level transit fare information. Returned only if fare information is available for the entire itinerary. Get Metro Area Info API can be requested to confirm if fare information is available in the metro area.

itineraryId
  • string

A unique identifier of the returned itinerary.

legs

An array summarizing the legs of this itinerary.

numberOfLegs
  • integer

Number of legs.

travelTimeInSeconds
  • integer

Estimated travel time in seconds.

JsonFormat

Desired format of the response. Only json format is supported.

Name Type Description
json
  • string

The JavaScript Object Notation Data Interchange Format

LegFare

Leg level public transit fare information. Returned only if fare information is available for the entire itinerary level and supported by the local transit agency.

Name Type Description
fares

Detailed fare information for the leg.

LegType

Name Type Description
Bicycle
  • string

Bicycle

Bus
  • string

Bus

Cable
  • string

Cable Car

Ferry
  • string

Ferry

Funicular
  • string

Funicular

Gondola
  • string

Gondola

PathWayWalk
  • string

A Leg describing a walk within a compound, e.g. Central Station

Rail
  • string

Rail

Subway
  • string

Subway

Tram
  • string

Tram

Wait
  • string

A Leg describing a wait for the next public transit leg

WaitOnVehicle
  • string

It’s necessary to wait for the next leg on the same vehicle (i.e. the bus will only change its line number)

Walk
  • string

Pedestrian walk

ODataError

This object is returned when an error occurs in the Azure Maps API.

Name Type Description
code
  • string

The ODataError code.

details

This object is returned when an error occurs in the Azure Maps API.

message
  • string

If available, a human-readable description of the error.

target
  • string

If available, the target causing the error.

ODataErrorResponse

This response object is returned when an error occurs in the Azure Maps API.

Name Type Description
error

This object is returned when an error occurs in the Azure Maps API.

OriginType

The type of the origin. By default originType=position, specified as a comma separated string composed by latitude followed by longitude, e.g., "47.641268,-122.125679”.

Name Type Description
position
  • string

The origin of the route as a comma separated string composed by latitude followed by longitude e.g. "47.641268,-122.125679".

stopId
  • string

The unique Azure Maps identifier for the respective public transit stop. When referring to public transit stops over time, it is recommended to use stopId since it will not change, as long as the physical stop exists

stopKey
  • string

The GTFS stop Id. GTFS stop Ids are provided by the transit authority and are subject to change.
Note: When this value is used, the metroId parameter is required.

Price

Name Type Description
amount
  • integer

Price of the ticket in cents. For example, $5.00 is returned as ‘500’.

currencyCode
  • string

Currency code, for example for US dollars “USD”.

RouteItineraryLeg

Name Type Description
caption
  • string

For Public Transit legs the caption of the line serving the leg, for example, line number.

legEndTime
  • string

End time for the leg in ISO 8601 format, e.g. 1996-12-19T19:39:57-08:00.

legFare

Leg level public transit fare information. Returned only if fare information is available for the entire itinerary.

legStartTime
  • string

Start time for the leg in ISO 8601 format, e.g. 1996-12-19T19:39:57-08:00.

legType

The travel mode of the leg.

lengthInMeters
  • integer

The total distance of the leg in meters.

Tickets

An array describing the individual prices of each of the tickets that the user is expected to purchase throughout this itinerary. The list isn’t ordered.

Name Type Description
amount
  • integer

Price of the ticket in cents. For example, $5.00 is returned as ‘500’.

currencyCode
  • string

Currency code, for example for US dollars “USD”.

TimeType

Specifies whether the time signifies departure time or arrival time. If not defined, default value is 'departure'.

Name Type Description
arrival
  • string

arrival at the destination point. Requires that 'time' value must be in the future.

departure
  • string

Request departure at the destination point. Requires that 'time' value must be now or in the future.

last
  • string

Request the last lines for the day.

TransitRouteResponse

This object is returned from a successful Get Transit Stop Info call

Name Type Description
results

TransitRouteType

The type of route requested. If not specified, 'optimal' will be used.

Name Type Description
leastTransfers
  • string

Route with least transfers.

leastWalk
  • string

Route with least walk.

optimal
  • string

The best optimal route.