在 Azure IoT Central 解決方案中使用位置資料Use location data in an Azure IoT Central solution

本文說明如何在 IoT Central 應用程式中使用位置資料。This article shows you how to use location data in an IoT Central application. 連線至 IoT Central 的裝置可以將位置資料傳送為遙測串流,或使用裝置屬性來報告位置資料。A device connected to IoT Central can send location data as telemetry stream or use a device property to report location data.

您可以使用位置資料來:You can use the location data to:

  • 將報告的位置繪製在地圖上。Plot the reported location on a map.
  • 繪製遙測位置記錄 om 的地圖。Plot the telemetry location history om a map.
  • 建立地理柵欄規則,以在裝置進入或離開特定區域時通知操作員。Create geofencing rules to notify an operator when a device enters or leaves a specific area.

將位置功能新增至裝置範本Add location capabilities to a device template

下列螢幕擷取畫面顯示裝置範本,其中包含使用位置資料的裝置屬性和遙測類型範例。The following screenshot shows a device template with examples of a device property and telemetry type that use location data. 定義會使用位置語義型別和 地理****位置 架構類型:The definitions use the location semantic type and the geolocation schema type:

顯示裝置範本中位置屬性定義的螢幕擷取畫面

如需參考, 數位 Twins 定義語言 (DTDL 這些功能的定義) 定義如下列程式碼片段所示:For reference, the Digital Twins Definition Language (DTDL) definitions for these capabilities look like the following snippet:

{
  "@type": [
    "Property",
    "Location"
  ],
  "displayName": {
    "en": "DeviceLocation"
  },
  "name": "DeviceLocation",
  "schema": "geopoint",
  "writable": false
},
{
  "@type": [
    "Telemetry",
    "Location"
  ],
  "displayName": {
    "en": "Tracking"
  },
  "name": "Tracking",
  "schema": "geopoint"
}

注意

Geopoint 架構類型不是 DTDL 規格的一部分。The geopoint schema type is not part of the DTDL specification. IoT Central 目前支援 geopoint 架構型別和 位置 語義型別,以提供回溯相容性。IoT Central currently supports the geopoint schema type and the location semantic type for backwards compatibility.

從裝置傳送位置資料Send location data from a device

當裝置針對上一節所示的 DeviceLocation 屬性傳送資料時,承載看起來會像下列 JSON 程式碼片段:When a device sends data for the DeviceLocation property shown in the previous section, the payload looks like the following JSON snippet:

{
  "DeviceLocation": {
    "lat": 47.64263,
    "lon": -122.13035,
    "alt": 0
  }
}

當裝置針對上一節顯示的 追蹤 遙測資料傳送資料時,承載看起來會像下列 JSON 程式碼片段:When a device sends data for the Tracking telemetry shown in the previous section, the payload looks like the following JSON snippet:

{
  "Tracking": {
    "lat": 47.64263,
    "lon": -122.13035,
    "alt": 0
  }
}

顯示裝置位置Display device location

您可以在 IoT Central 應用程式中的多個位置顯示位置資料。You can display location data in multiple places in your IoT Central application. 例如,在與個別裝置或儀表板相關聯的視圖上。For example, on views associated with an individual device or on dashboards.

當您建立裝置的視圖時,您可以選擇在地圖上繪製位置,或顯示個別的值:When you create a view for a device, you can choose to plot the location on a map, or show the individual values:

顯示位置資料範例視圖的螢幕擷取畫面

您可以將地圖底圖新增至儀表板,以繪製一或多個裝置的位置。You can add map tiles to a dashboard to plot the location of one or more devices. 當您新增地圖底圖來顯示位置遙測時,您可以在一段時間內繪製位置。When you add a map tile to show location telemetry, you can plot the location over a time period. 下列螢幕擷取畫面顯示模擬裝置在過去30分鐘內回報的位置:The following screenshot shows the location reported by a simulated device over the last 30 minutes:

顯示範例儀表板的螢幕擷取畫面,其中包含位置資料

建立地理柵欄規則Create a geofencing rule

您可以使用位置遙測來建立地理柵欄規則,以在裝置移入或移出矩形區域時產生警示。You can use location telemetry to create a geofencing rule that generates an alert when a device moves into or out of a rectangular area. 下列螢幕擷取畫面顯示的規則會使用四個條件來定義使用緯度和經度值的矩形區域。The following screenshot shows a rule that uses four conditions to define a rectangular area using latitude and longitude values. 當裝置移至矩形區域時,此規則會產生電子郵件:The rule generates an email when the device moves into the rectangular area:

顯示地理柵欄規則定義的螢幕擷取畫面

下一步Next steps

現在您已瞭解如何在 Azure IoT Central 應用程式中使用屬性,請參閱:Now that you've learned how to use properties in your Azure IoT Central application, see: