

# 設定 LoRaWAN 閘道的位置
<a name="lorawan-location-gateways"></a>

您將閘道新增至 AWS IoT Core for LoRaWAN 時，可以指定靜態位置資料。如果您已啟用 Amazon Location Service，位置資料會顯示在 Amazon Location 地圖上。

**注意**  
第三方的求解器不能與 LoRaWAN 閘道搭配使用。針對閘道應用，您仍然可以指定靜態位置座標並新增目的地。當求解器不用於計算位置時 (例如在閘道應用中)，準確度資訊將報告為 `0.0`。

您可以使用 AWS 管理主控台、AWS IoT Wireless API 或 AWS CLI 來設定閘道位置。

## 使用主控台設定閘道的位置
<a name="lorawan-location-gateways-console"></a>

若要使用 AWS 管理主控台 來設定閘道資源的位置，請先登入主控台，然後前往 AWS IoT 主控台的 [https://console.aws.amazon.com/iot/home#/wireless/gateways](https://console.aws.amazon.com/iot/home#/wireless/gateways) (閘道) 中樞頁面。

**新增位置資訊**  
為閘道新增位置組態

1. 在 **Gateways** (閘道) 中樞頁面，選擇 **Add gateway** (新增閘道)。

1. 輸入閘道的 EUI、頻帶 (RFRegion)，以及任何其他閘道詳細資訊和 LoRaWAN 組態資訊。如需詳細資訊，請參閱[使用主控台新增閘道](lorawan-onboard-gateway-add.md#lorawan-onboard-gateway-console)。

1. 前往**Position information - Optional** (位置資訊 - 選擇性)，使用經緯度坐標以及高度座標 (選用) 來輸入閘道的位置資訊。位置資訊以 WGS84 座標系統為基礎。

**檢視閘道的位置**  
設定閘道的位置後，AWS IoT Core for LoRaWAN 會建立名為 `iotwireless.map` 的 Amazon Location 地圖。您可以在 **Position** (位置) 索引標籤中的閘道詳細資訊頁面上查看此地圖。根據您指定的位置座標，閘道位置會在地圖上顯示為標記。您可以放大或縮小標記，清楚檢視閘道在地圖上的位置。在 **Position** (位置) 索引標籤中，您也可看到準確度資訊和決定閘道位置的時間戳記

**注意**  
如果沒有安裝 Amazon Location Service 地圖，您會看到一則訊息，指明您必須使用 Amazon Location Service 來存取地圖和檢視閘道位置。使用 Amazon Location Service 地圖可能會向您的 AWS 帳戶 收取額外費用。如需詳細資訊，請參閱 [AWS IoT Core 定價](https://aws.amazon.com/iot-core/pricing/)。

地圖 `iotwireless.map` 作為地圖資料的來源，透過 `Get` API 操作存取，例如 [https://docs.aws.amazon.com/location-maps/latest/APIReference/API_GetMapTile.html](https://docs.aws.amazon.com/location-maps/latest/APIReference/API_GetMapTile.html)。如需 `Get` API 與地圖搭配使用的相關資訊，請參閱 [Amazon Location Service API reference](https://docs.aws.amazon.com/location-maps/latest/APIReference/Welcome.html) (《Amazon Location Service API 參考》)。

如需有關此地圖的其他詳細資訊，請前往 Amazon Location Service 主控台，選擇 **maps** (地圖)，然後選擇 [iotwireless.map](https://console.aws.amazon.com/location/maps/home#/describe/iotwireless.map)。如需詳細資訊，請參閱《Amazon Location Service 開發人員指南》中的[地圖](https://docs.aws.amazon.com/location/latest/developerguide/map-concepts.html)。

**更新閘道的位置組態**  
若要變更閘道的位置組態，請在閘道詳細資訊頁面中選擇 **Edit** (編輯)，然後更新位置資訊和目的地。

**注意**  
無法取得有關歷史位置資料的資訊。更新閘道的位置座標時，即會覆寫先前報告的位置資料。更新位置之後，您會在閘道詳細資訊的 **Position** (位置) 索引標籤中看到新的位置資訊。時間戳記的變更表示它對應到閘道的最後一個已知位置。

## 使用 API 設定閘道的位置
<a name="lorawan-location-gateways-api"></a>

您可以使用 AWS IoT Wireless API 或 AWS CLI 指定位置資訊並設定閘道位置。

**重要**  
不再支援下列 API 動作：[ UpdatePosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_UpdatePosition.html)、[GetPosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_GetPosition.html)、[PutPositionConfiguration](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_PutPositionConfiguration.html)、[GetPositionConfiguration](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_GetPositionConfiguration.html) 以及 [ListPositionConfigurations](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_ListPositionConfigurations.html)。用於更新和擷取位置資訊的呼叫應改為使用 [GetResourcePosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_GetResourcePosition.html) 和 [UpdateResourcePosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_UpdateResourcePosition.html) API 操作。

### 新增位置資訊
<a name="lorawan-location-gateways-api-add"></a>

若要為指定的無線閘道新增靜態位置資訊，請使用 [UpdateResourcePosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_UpdateResourcePosition.html) API 操作或 [update-resource-position](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/update-resource-position.html) CLI 命令來指定坐標。指定 `WirelessGateway` 作為 `ResourceType`、要更新之無線閘道的 ID 作為 `ResourceIdentifier`，以及定位資訊作為 GeoJSON 承載。

```
aws iotwireless update-resource-position \ 
    --resource-type WirelessGateway \ 
    --resource-id {{"12345678-a1b2-3c45-67d8-e90fa1b2c34d"}} \ 
    --cli-input-json {{file://gatewayposition.json}}
```

下列顯示 `{{gatewayposition.json}}` 檔案的內容。

**gatewayposition.json 的內容**

```
{ 
     "type": "Point",
     "coordinates": {{[33.3318, -22.2155, 13.123]}},
     "properties": {
          "timestamp": {{"2018-11-30T18:35:24Z"}}
      }
}
```

執行這個命令不會產生任何輸出。若要查看您指定的位置資訊，請使用 `GetResourcePosition` API 操作。

### 取得位置資訊
<a name="lorawan-location-devices-api-get"></a>

若要取得指定無線閘道的位置資訊，請使用 [ GetResourcePosition](https://docs.aws.amazon.com/iot-wireless/2020-11-22/apireference/API_GetResourcePosition.html) API 操作或 [get-resource-position](https://docs.aws.amazon.com/cli/latest/reference/iotwireless/get-position.html) CLI 命令。指定 `WirelessGateway` 作為 `resourceType`，並提供無線閘道的 ID 作為 `resourceIdentifier`。

```
aws iotwireless get-resource-position \ 
    --resource-type WirelessGateway \ 
    --resource-id {{"12345678-a1b2-3c45-67d8-e90fa1b2c34d"}}
```

執行這個命令會將無線閘道位置資訊顯示為 GeoJSON 承載。您將看到的資訊包含位置坐標、位置資訊類型、其他屬性，例如對應於閘道最後已知位置的時間戳記。

```
{
    {
    "type": "Point",
     "coordinates": [33.3318,-22.2155,13.123],
     "properties": {
         "timestamp": "2018-11-30T18:35:24Z"
         }
    }
}
```