

# 配置 LoRaWAN 网关的位置
<a name="lorawan-location-gateways"></a>

将网关添加到 适用于 LoRaWAN 的 AWS IoT Core 时，您可以指定静态位置数据。如果您激活了 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 坐标系。

**查看网关的位置**  
配置网关位置后，适用于 LoRaWAN 的 AWS IoT Core 会创建一个称为 `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 参考](https://docs.aws.amazon.com/location-maps/latest/APIReference/Welcome.html)。

要获取有关此地图的其他详细信息，请转到 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"
         }
    }
}
```