Skip to content

Commit b88deba

Browse files
Merge pull request #265613 from stevemunk/tutorial-geofence-update-2
Replacing references to the dataRegistry service with the data service
2 parents 7e9cc9c + e34f59d commit b88deba

File tree

1 file changed

+126
-25
lines changed

1 file changed

+126
-25
lines changed

articles/azure-maps/tutorial-geofence.md

Lines changed: 126 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 'Tutorial: Create a geofence and track devices on a Microsoft Azure Map'
33
description: Tutorial on how to set up a geofence. See how to track devices relative to the geofence by using the Azure Maps Spatial service
44
author: eriklindeman
55
ms.author: eriklind
6-
ms.date: 09/14/2023
6+
ms.date: 02/07/2024
77
ms.topic: tutorial
88
ms.service: azure-maps
99
services: azure-maps
@@ -21,11 +21,11 @@ Consider the following scenario:
2121
Azure Maps provides services to support the tracking of equipment entering and exiting the construction area. In this tutorial, you will:
2222

2323
> [!div class="checklist"]
24-
>
25-
> * Upload [Geofencing GeoJSON data] that defines the construction site areas you want to monitor. You'll upload geofences as polygon coordinates to your Azure storage account, then use the [data registry] service to register that data with your Azure Maps account.
24+
> <!-- > * Upload [Geofencing GeoJSON data] that defines the construction site areas you want to monitor. You'll upload geofences as polygon coordinates to your Azure storage account, then use the [data registry] service to register that data with your Azure Maps account. --->
25+
> * Upload [Geofencing GeoJSON data] that defines the construction site areas you want to monitor. You'll use the [Data Upload API] to upload geofences as polygon coordinates to your Azure Maps account.
2626
> * Set up two [logic apps] that, when triggered, send email notifications to the construction site operations manager when equipment enters and exits the geofence area.
2727
> * Use [Azure Event Grid] to subscribe to enter and exit events for your Azure Maps geofence. You set up two webhook event subscriptions that call the HTTP endpoints defined in your two logic apps. The logic apps then send the appropriate email notifications of equipment moving beyond or entering the geofence.
28-
> * Use [Search Geofence Get API] to receive notifications when a piece of equipment exits and enters the geofence areas.
28+
> * Use [Spatial Geofence Get API] to receive notifications when a piece of equipment exits and enters the geofence areas.
2929
3030
## Prerequisites
3131

@@ -39,11 +39,47 @@ This tutorial uses the [Postman] application, but you can use a different API de
3939
>
4040
> In the URL examples, replace `{Your-Azure-Maps-Subscription-key}` with your Azure Maps subscription key.
4141
42+
## Create an Azure Maps account with a global region
43+
44+
The Geofence API async event requires the region property of your Azure Maps account be set to ***Global***. This setting isn't given as an option when creating an Azure Maps account in the Azure portal, however you do have several other options for creating a new Azure Maps account with the *global* region setting. This section lists the three methods that can be used to create an Azure Maps account with the region set to *global*.
45+
46+
> [!NOTE]
47+
> The `location` property in both the ARM template and PowerShell `New-AzMapsAccount` command refer to the same property as the `Region` field in the Azure portal.
48+
4249
## Upload geofencing GeoJSON data
4350

4451
This tutorial demonstrates how to upload geofencing GeoJSON data that contains a `FeatureCollection`. The `FeatureCollection` contains two geofences that define polygonal areas within the construction site. The first geofence has no time expiration or restrictions. The second can only be queried against during business hours (9:00 AM-5:00 PM in the Pacific Time zone), and will no longer be valid after January 1, 2022. For more information on the GeoJSON format, see [Geofencing GeoJSON data].
4552

46-
Create the geofence JSON file using the following geofence data. You'll upload this file into your Azure storage account next.
53+
>[!TIP]
54+
>You can update your geofencing data at any time. For more information, see [Data Upload API].
55+
To upload the geofencing GeoJSON data:
56+
57+
1. In the Postman app, select **New**.
58+
59+
2. In the **Create New** window, select **HTTP Request**.
60+
61+
3. Enter a **Request name** for the request, such as *POST GeoJSON Data Upload*.
62+
63+
4. Select the **POST** HTTP method.
64+
65+
5. Enter the following URL. The request should look like the following URL:
66+
67+
```HTTP
68+
https://{geography}.atlas.microsoft.com/mapData?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2.0&dataFormat=geojson
69+
```
70+
71+
The `geojson` parameter in the URL path represents the data format of the data being uploaded.
72+
73+
> [!NOTE]
74+
> Replace {geography} with your geographic scope. For more information, see [Azure Maps service geographic scope] and the [Spatial Geofence Get API].
75+
76+
6. Select the **Body** tab.
77+
78+
7. In the dropdown lists, select **raw** and **JSON**.
79+
80+
8. Copy the following GeoJSON data, and then paste it in the **Body** window:
81+
82+
<!--Create the geofence JSON file using the following geofence data. You'll upload this file into your Azure storage account next.-->
4783
4884
```JSON
4985
{
@@ -131,10 +167,79 @@ Create the geofence JSON file using the following geofence data. You'll upload t
131167
}
132168
```
133169

134-
Follow the steps outlined in the [How to create data registry] article to upload the geofence JSON file into your Azure storage account and register it in your Azure Maps account.
170+
<!--Follow the steps outlined in the [How to create data registry] article to upload the geofence JSON file into your Azure storage account and register it in your Azure Maps account.-->
171+
172+
9. Select **Send**.
173+
174+
10. In the response window, select the **Headers** tab.
175+
176+
11. Copy the value of the **Operation-Location** key, which is the `status URL`. The `status URL` is used to check the status of the GeoJSON data upload.
177+
178+
```http
179+
https://{geography}.atlas.microsoft.com/mapData/operations/{operationId}?api-version=2.0
180+
```
181+
182+
### Check the GeoJSON data upload status
183+
184+
To check the status of the GeoJSON data and retrieve its unique ID (`udid`):
185+
186+
1. Select **New**.
187+
188+
2. In the **Create New** window, select **HTTP Request**.
189+
190+
3. Enter a **Request name** for the request, such as *GET Data Upload Status*.
191+
192+
4. Select the **GET** HTTP method.
193+
194+
5. Enter the `status URL` you copied in [Upload Geofencing GeoJSON data]. The request should look like the following URL:
195+
196+
```HTTP
197+
https://{geography}.atlas.microsoft.com/mapData/{operationId}?api-version=2.0&subscription-key={Your-Azure-Maps-Subscription-key}
198+
```
199+
200+
6. Select **Send**.
201+
202+
7. In the response window, select the **Headers** tab.
203+
204+
8. Copy the value of the **Resource-Location** key, which is the `resource location URL`. The `resource location URL` contains the unique identifier (`udid`) of the uploaded data. Save the `udid` to query the Get Geofence API in the last section of this tutorial.
205+
206+
### (Optional) Retrieve GeoJSON data metadata
207+
208+
You can retrieve metadata from the uploaded data. The metadata contains information like the resource location URL, creation date, updated date, size, and upload status.
209+
210+
To retrieve content metadata:
211+
212+
1. Select **New**.
213+
214+
2. In the **Create New** window, select **HTTP Request**.
215+
216+
3. Enter a **Request name** for the request, such as *GET Data Upload Metadata*.
217+
218+
4. Select the **GET** HTTP method.
219+
220+
5. Enter the `resource Location URL` you copied in [Check the GeoJSON data upload status]. The request should look like the following URL:
221+
222+
```http
223+
https://{geography}.atlas.microsoft.com/mapData/metadata/{udid}?api-version=2.0&subscription-key={Your-Azure-Maps-Subscription-key}
224+
```
225+
226+
6. In the response window, select the **Body** tab. The metadata should look like the following JSON fragment:
135227
228+
```json
229+
{
230+
"udid": "{udid}",
231+
"location": "https://{geography}.atlas.microsoft.com/mapData/6ebf1ae1-2a66-760b-e28c-b9381fcff335?api-version=2.0",
232+
"created": "5/18/2021 8:10:32 PM +00:00",
233+
"updated": "5/18/2021 8:10:37 PM +00:00",
234+
"sizeInBytes": 946901,
235+
"uploadStatus": "Completed"
236+
}
237+
```
238+
239+
<!--
136240
> [!IMPORTANT]
137241
> Make sure to make a note of the unique identifier (`udid`) value, you will need it. The `udid` is how you reference the geofence you uploaded into your Azure storage account from your source code and HTTP requests.
242+
-->
138243
139244
## Create workflows in Azure Logic Apps
140245
@@ -248,15 +353,12 @@ Each of the following sections makes API requests by using the five different lo
248353
249354
4. Select the **GET** HTTP method.
250355
251-
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data section]).
356+
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data] section).
252357
253358
```HTTP
254359
https://{geography}.atlas.microsoft.com/spatial/geofence/json?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2022-08-01&deviceId=device_01&udid={udid}&lat=47.638237&lon=-122.1324831&searchBuffer=5&isAsync=True&mode=EnterAndExit
255360
```
256361

257-
> [!NOTE]
258-
> Replace {geography} with your geographic scope. For more information, see [Azure Maps service geographic scope] and the [Spatial Geofence Get API].
259-
260362
6. Select **Send**.
261363

262364
7. The response should like the following GeoJSON fragment:
@@ -287,7 +389,7 @@ Each of the following sections makes API requests by using the five different lo
287389
}
288390
```
289391

290-
In the preceding GeoJSON response, the negative distance from the main site geofence means that the equipment is inside the geofence. The positive distance from the subsite geofence means that the equipment is outside the subsite geofence. Because this is the first time this device has been located inside the main site geofence, the `isEventPublished` parameter is set to `true`. The Operations Manager receives an email notification that equipment has entered the geofence.
392+
In the preceding GeoJSON response, the negative distance from the main site geofence means that the equipment is inside the geofence. The positive distance from the subsite geofence means that the equipment is outside the subsite geofence. Since it's the first time this device was located inside the main site geofence, the `isEventPublished` parameter is set to `true`. The Operations Manager receives an email notification that equipment entered the geofence.
291393

292394
### Location 2 (47.63800,-122.132531)
293395

@@ -299,7 +401,7 @@ In the preceding GeoJSON response, the negative distance from the main site geof
299401

300402
4. Select the **GET** HTTP method.
301403

302-
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data section]).
404+
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data] section).
303405

304406
```HTTP
305407
https://{geography}.atlas.microsoft.com/spatial/geofence/json?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2022-08-01&deviceId=device_01&udId={udId}&lat=47.63800&lon=-122.132531&searchBuffer=5&isAsync=True&mode=EnterAndExit
@@ -335,7 +437,7 @@ In the preceding GeoJSON response, the negative distance from the main site geof
335437
}
336438
````
337439

338-
In the preceding GeoJSON response, the equipment has remained in the main site geofence and hasn't entered the subsite geofence. As a result, the `isEventPublished` parameter is set to `false`, and the Operations Manager doesn't receive any email notifications.
440+
In the preceding GeoJSON response, the equipment remained in the main site geofence and didn't enter the subsite geofence. As a result, the `isEventPublished` parameter is set to `false`, and the Operations Manager doesn't receive any email notifications.
339441

340442
### Location 3 (47.63810783315048,-122.13336020708084)
341443

@@ -347,7 +449,7 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
347449

348450
4. Select the **GET** HTTP method.
349451

350-
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data section]).
452+
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data] section).
351453

352454
```HTTP
353455
https://{geography}.atlas.microsoft.com/spatial/geofence/json?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2022-08-01&deviceId=device_01&udid={udid}&lat=47.63810783315048&lon=-122.13336020708084&searchBuffer=5&isAsync=True&mode=EnterAndExit
@@ -383,7 +485,7 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
383485
}
384486
````
385487

386-
In the preceding GeoJSON response, the equipment has remained in the main site geofence, but has entered the subsite geofence. As a result, the `isEventPublished` parameter is set to `true`. The Operations Manager receives an email notification indicating that the equipment has entered a geofence.
488+
In the preceding GeoJSON response, the equipment remained in the main site geofence, and entered the subsite geofence. As a result, the `isEventPublished` parameter is set to `true`. The Operations Manager receives an email notification indicating that the equipment entered a geofence.
387489

388490
>[!NOTE]
389491
>If the equipment had moved into the subsite after business hours, no event would be published and the operations manager wouldn't receive any notifications.
@@ -398,7 +500,7 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
398500

399501
4. Select the **GET** HTTP method.
400502

401-
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data section]).
503+
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data] section).
402504

403505
```HTTP
404506
https://{geography}.atlas.microsoft.com/spatial/geofence/json?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2022-08-01&deviceId=device_01&udid={udid}&lat=47.637988&userTime=2023-01-16&lon=-122.1338344&searchBuffer=5&isAsync=True&mode=EnterAndExit
@@ -428,7 +530,7 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
428530
}
429531
````
430532

431-
In the preceding GeoJSON response, the equipment has remained in the main site geofence, but has exited the subsite geofence. Notice, however, that the `userTime` value is after the `expiredTime` as defined in the geofence data. As a result, the `isEventPublished` parameter is set to `false`, and the Operations Manager doesn't receive an email notification.
533+
In the preceding GeoJSON response, the equipment remained in the main site geofence, but exited the subsite geofence. Notice, however, that the `userTime` value is after the `expiredTime` as defined in the geofence data. As a result, the `isEventPublished` parameter is set to `false`, and the Operations Manager doesn't receive an email notification.
432534

433535
### Location 5 (47.63799, -122.134505)
434536

@@ -440,7 +542,7 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
440542

441543
4. Select the **GET** HTTP method.
442544

443-
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data section]).
545+
5. Enter the following URL. The request should look like the following URL (replace `{udid}` with the `udid` you saved in the [Upload Geofencing GeoJSON data] section).
444546

445547
```HTTP
446548
https://{geography}.atlas.microsoft.com/spatial/geofence/json?subscription-key={Your-Azure-Maps-Subscription-key}&api-version=2022-08-01&deviceId=device_01&udid={udid}&lat=47.63799&lon=-122.134505&searchBuffer=5&isAsync=True&mode=EnterAndExit
@@ -476,9 +578,9 @@ In the preceding GeoJSON response, the equipment has remained in the main site g
476578
}
477579
````
478580

479-
In the preceding GeoJSON response, the equipment has exited the main site geofence. As a result, the `isEventPublished` parameter is set to `true`, and the Operations Manager receives an email notification indicating that the equipment has exited a geofence.
581+
In the preceding GeoJSON response, the equipment exited the main site geofence. As a result, the `isEventPublished` parameter is set to `true`, and the Operations Manager receives an email notification indicating that the equipment exited a geofence.
480582

481-
You can also [Send email notifications using Event Grid and Logic Apps]. For more information,see [Event handlers in Azure Event Grid].
583+
You can also [Send email notifications using Event Grid and Logic Apps]. For more information, see [Event handlers in Azure Event Grid].
482584

483585
## Clean up resources
484586

@@ -495,18 +597,17 @@ There are no resources that require cleanup.
495597
[Azure portal]: https://portal.azure.com
496598
[Azure storage account]: /azure/storage/common/storage-account-create?tabs=azure-portal
497599
[Billing and pricing models]: /azure/logic-apps/logic-apps-pricing#standard-pricing
498-
[data registry]: /rest/api/maps/data-registry
600+
[Check the GeoJSON data upload status]: #check-the-geojson-data-upload-status
601+
[Data Upload API]: /rest/api/maps/data/upload
499602
[Geofencing GeoJSON data]: geofence-geojson.md
500603
[Handle content types in Azure Logic Apps]: ../logic-apps/logic-apps-content-type.md
501-
[How to create data registry]: how-to-create-data-registries.md
502604
[logic app]: ../event-grid/handler-webhooks.md#logic-apps
503605
[logic apps]: ../event-grid/handler-webhooks.md#logic-apps
504606
[Postman]: https://www.postman.com
505-
[Search Geofence Get API]: /rest/api/maps/spatial/getgeofence
506607
[Send email notifications using Event Grid and Logic Apps]: ../event-grid/publish-iot-hub-events-to-logic-apps.md
507-
[Spatial Geofence Get API]: /rest/api/maps/spatial/getgeofence
608+
[Spatial Geofence Get API]: /rest/api/maps/spatial/get-geofence
508609
[subscription key]: quick-demo-map-app.md#get-the-subscription-key-for-your-account
509610
[Event handlers in Azure Event Grid]: ../event-grid/event-handlers.md
510611
[three event types]: ../event-grid/event-schema-azure-maps.md
511612
[Tutorial: Send email notifications about Azure IoT Hub events using Event Grid and Logic Apps]: ../event-grid/publish-iot-hub-events-to-logic-apps.md
512-
[Upload Geofencing GeoJSON data section]: #upload-geofencing-geojson-data
613+
[Upload Geofencing GeoJSON data]: #upload-geofencing-geojson-data

0 commit comments

Comments
 (0)