|
| 1 | +--- |
| 2 | +title: How to request real-time data in Azure Maps | Microsoft Docs |
| 3 | +description: Request real-time data using the Azure Maps Mobility service. |
| 4 | +author: walsehgal |
| 5 | +ms.author: v-musehg |
| 6 | +ms.date: 06/05/2019 |
| 7 | +ms.topic: conceptual |
| 8 | +ms.service: azure-maps |
| 9 | +services: azure-maps |
| 10 | +manager: philmea |
| 11 | +ms.custom: mvc |
| 12 | +--- |
| 13 | + |
| 14 | +# Request real-time data using the Azure Maps Mobility Service |
| 15 | + |
| 16 | +This article shows you how to use Azure Maps [Mobility Service](https://aka.ms/AzureMapsMobilityService) to request real-time transit data. |
| 17 | + |
| 18 | +In this article you will learn how to: |
| 19 | + |
| 20 | + |
| 21 | + * Request next real-time arrivals for all lines arriving at the given stop |
| 22 | + * Request real-time information for a given bike docking station. |
| 23 | + |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +To make any calls to the Azure Maps public transit APIs, you need a Maps account and key. For information on creating an account and retrieving a key, see [How to manage your Azure Maps account and keys](how-to-manage-account-keys.md). |
| 28 | + |
| 29 | +This article uses the [Postman app](https://www.getpostman.com/apps) to build REST calls. You can use any API development environment that you prefer. |
| 30 | + |
| 31 | + |
| 32 | +## Request real-time arrivals for a stop |
| 33 | + |
| 34 | +In order to request real-time arrivals data for a particular public transit stop, you will need to make a request to the [Real-time Arrivals API](https://aka.ms/AzureMapsMobilityRealTimeArrivals) of the Azure Maps [Mobility Service](https://aka.ms/AzureMapsMobilityService). You will need the **metroID** and **stopID** to complete the request. To learn more about how to request these parameters, see our How-to guide to [request public transit routes](https://aka.ms/AMapsHowToGuidePublicTransitRouting). |
| 35 | + |
| 36 | +Let's use "522" as our metro ID, which is the metro ID for "Seattle–Tacoma–Bellevue, WA" area, and use the stop ID "2060603", which is a bus stop at "Ne 24th St & 162nd Ave Ne, Bellevue WA". To request next five real-time arrivals data for all next live arrivals at this stop, complete the following steps: |
| 37 | + |
| 38 | +1. Create a collection in which to store the requests. In the Postman app, select **New**. In the **Create New** window, select **Collection**. Name the collection and select the **Create** button. |
| 39 | + |
| 40 | +2. To create the request, select **New** again. In the **Create New** window, select **Request**. Enter a **Request name** for the request, select the collection you created in the previous step as the location in which to save the request, and then select **Save**. |
| 41 | + |
| 42 | +  |
| 43 | + |
| 44 | +3. Select the GET HTTP method on the builder tab and enter the following URL to create a GET request. |
| 45 | + |
| 46 | + ```HTTP |
| 47 | + https://atlas.microsoft.com/mobility/realtime/arrivals/json?subscription-key={subscription-key}&api-version=1.0&metroId=522&query=2060603&transitType=bus |
| 48 | + ``` |
| 49 | +
|
| 50 | +4. After a successful request, you will receive the following response. Notice that parameter 'scheduleType' defines whether the estimated arrival time is based on real-time or static data. |
| 51 | +
|
| 52 | + ```JSON |
| 53 | + { |
| 54 | + "results": [ |
| 55 | + { |
| 56 | + "arrivalMinutes": 4, |
| 57 | + "scheduleType": "realTime", |
| 58 | + "patternId": 3860436, |
| 59 | + "line": { |
| 60 | + "lineId": 2756599, |
| 61 | + "lineGroupId": 666063, |
| 62 | + "direction": "forward", |
| 63 | + "agencyId": 5872, |
| 64 | + "agencyName": "Metro Transit", |
| 65 | + "lineNumber": "226", |
| 66 | + "lineDestination": "Bellevue Transit Center Crossroads", |
| 67 | + "transitType": "Bus" |
| 68 | + }, |
| 69 | + "stop": { |
| 70 | + "stopId": 2060603, |
| 71 | + "stopKey": "71300", |
| 72 | + "stopName": "NE 24th St & 162nd Ave NE", |
| 73 | + "position": { |
| 74 | + "latitude": 47.631504, |
| 75 | + "longitude": -122.125275 |
| 76 | + }, |
| 77 | + "mainTransitType": "Bus", |
| 78 | + "mainAgencyId": 5872, |
| 79 | + "mainAgencyName": "Metro Transit" |
| 80 | + } |
| 81 | + }, |
| 82 | + { |
| 83 | + "arrivalMinutes": 30, |
| 84 | + "scheduleType": "scheduledTime", |
| 85 | + "patternId": 3860436, |
| 86 | + "line": { |
| 87 | + "lineId": 2756599, |
| 88 | + "lineGroupId": 666063, |
| 89 | + "direction": "forward", |
| 90 | + "agencyId": 5872, |
| 91 | + "agencyName": "Metro Transit", |
| 92 | + "lineNumber": "226", |
| 93 | + "lineDestination": "Bellevue Transit Center Crossroads", |
| 94 | + "transitType": "Bus" |
| 95 | + }, |
| 96 | + "stop": { |
| 97 | + "stopId": 2060603, |
| 98 | + "stopKey": "71300", |
| 99 | + "stopName": "NE 24th St & 162nd Ave NE", |
| 100 | + "position": { |
| 101 | + "latitude": 47.631504, |
| 102 | + "longitude": -122.125275 |
| 103 | + }, |
| 104 | + "mainTransitType": "Bus", |
| 105 | + "mainAgencyId": 5872, |
| 106 | + "mainAgencyName": "Metro Transit" |
| 107 | + } |
| 108 | + } |
| 109 | + ] |
| 110 | + } |
| 111 | +
|
| 112 | +
|
| 113 | +## Real-time availability and vacancy information for bike docking station |
| 114 | +
|
| 115 | +The [Get Transit Dock Info API](https://aka.ms/AzureMapsMobilityTransitDock) of the Azure Maps Mobility Service, allows to request static and real-time information for a given bike or scooter docking station. We will make a request to get real-time data for a docking station for bikes. |
| 116 | +
|
| 117 | +In order to make a request to the Get Transit Dock Info API, you will need the **dockId** for that station. You can get the dock ID by making a search request to the [Get Nearby Transit API](https://aka.ms/AzureMapsMobilityNearbyTransit) and setting the **objectType** parameter to "bikeDock". Follow the steps below to get real-time data of a docking station for bikes. |
| 118 | +
|
| 119 | +
|
| 120 | +### Get dock ID |
| 121 | +
|
| 122 | +To get **dockID**, follow the steps below to make a request to the Get Nearby Transit API: |
| 123 | +
|
| 124 | +1. In Postman, click **New Request** | **GET request** and name it **Get dock ID**. |
| 125 | +
|
| 126 | +2. On the Builder tab, select the **GET** HTTP method, enter the following request URL, and click **Send**. |
| 127 | + |
| 128 | + ```HTTP |
| 129 | + https://atlas.microsoft.com/mobility/transit/nearby/json?subscription-key={subscription-key}&api-version=1.0&metroId=121&query=40.7663753,-73.9627498&radius=100&objectType=bikeDock |
| 130 | + ``` |
| 131 | +
|
| 132 | +3. After a successful request, you will receive the following response. Notice that we now have the **id** in the response, which can be used later as a query parameter in the request to the Get Transit Dock Info API. |
| 133 | +
|
| 134 | + ```JSON |
| 135 | + { |
| 136 | + "results": [ |
| 137 | + { |
| 138 | + "id": "121---4640799", |
| 139 | + "type": "bikeDock", |
| 140 | + "objectDetails": { |
| 141 | + "availableVehicles": 0, |
| 142 | + "vacantLocations": 30, |
| 143 | + "lastUpdated": "2019-05-21T20:06:59-04:00", |
| 144 | + "operatorInfo": { |
| 145 | + "id": "80", |
| 146 | + "name": "Citi Bike" |
| 147 | + } |
| 148 | + }, |
| 149 | + "position": { |
| 150 | + "latitude": 40.767128, |
| 151 | + "longitude": -73.962243 |
| 152 | + }, |
| 153 | + "viewport": { |
| 154 | + "topLeftPoint": { |
| 155 | + "latitude": 40.768039, |
| 156 | + "longitude": -73.963413 |
| 157 | + }, |
| 158 | + "btmRightPoint": { |
| 159 | + "latitude": 40.766216, |
| 160 | + "longitude": -73.961072 |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + ] |
| 165 | + } |
| 166 | + ``` |
| 167 | +
|
| 168 | +
|
| 169 | +### Get real-time bike dock status |
| 170 | +
|
| 171 | +Follow the steps below to make a request to the Get Transit Dock Info API to get real-time data for the selected dock. |
| 172 | +
|
| 173 | +1. In Postman, click **New Request** | **GET request** and name it **Get real-time dock data**. |
| 174 | +
|
| 175 | +2. On the Builder tab, select the **GET** HTTP method, enter the following request URL, and click **Send**. |
| 176 | + |
| 177 | + ```HTTP |
| 178 | + https://atlas.microsoft.com/mobility/transit/dock/json?subscription-key={subscription-key}&api-version=1.0&query=121---4640799 |
| 179 | + ``` |
| 180 | +
|
| 181 | +3. After a successful request, you will receive a response of the following structure: |
| 182 | +
|
| 183 | + ```JSON |
| 184 | + { |
| 185 | + "availableVehicles": 1, |
| 186 | + "vacantLocations": 29, |
| 187 | + "position": { |
| 188 | + "latitude": 40.767128, |
| 189 | + "longitude": -73.962246 |
| 190 | + }, |
| 191 | + "lastUpdated": "2019-05-21T20:26:47-04:00", |
| 192 | + "operatorInfo": { |
| 193 | + "id": "80", |
| 194 | + "name": "Citi Bike" |
| 195 | + } |
| 196 | + } |
| 197 | + ``` |
| 198 | +
|
| 199 | +
|
| 200 | +## Next steps |
| 201 | +
|
| 202 | +Learn how to request transit data using Mobility Service: |
| 203 | +
|
| 204 | +> [!div class="nextstepaction"] |
| 205 | +> [How to request transit data](how-to-request-transit-data.md) |
| 206 | +
|
| 207 | +Explore the Azure Maps Mobility Service API documentation: |
| 208 | +
|
| 209 | +> [!div class="nextstepaction"] |
| 210 | +> [Mobility Service API documentation](https://aka.ms/AzureMapsMobilityService) |
0 commit comments