

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 將追蹤器連結至地理圍欄集合
<a name="associate-consumer"></a>

現在您已擁有地理圍欄集合和追蹤器，您可以將它們連結在一起，以便根據所有地理圍欄自動評估位置更新。如果您不想評估所有位置更新，或者，如果您沒有將一些位置儲存在追蹤器資源中，您可以[根據隨需的地理位置評估裝置位置](https://docs.aws.amazon.com/location/latest/developerguide/evaluate-geofences.html)。

根據地理圍欄評估裝置位置時，會產生事件。您可以將 動作設定為這些事件。如需您可以為地理圍欄事件設定之動作的詳細資訊，請參閱[使用 Amazon EventBridge 對 Amazon Location Service 事件做出反應](https://docs.aws.amazon.com/location/latest/developerguide/location-events.html)。

Amazon Location 事件包含產生它的裝置位置更新屬性，以及輸入或結束的地理圍欄的一些屬性。如需地理圍欄事件中包含之資料的詳細資訊，請參閱 [Amazon Location Service 的 Amazon EventBridge 事件範例](location-events.md#example-event)。

下列範例使用主控台 AWS CLI、 或 Amazon Location APIs 將追蹤器資源連結至地理圍欄集合。

------
#### [ Console ]

**使用 Amazon Location Service 主控台將追蹤器資源連結至地理圍欄集合**

1. 開啟位於 https：//[https://console.aws.amazon.com/location/](https://console.aws.amazon.com/location/home) 的 Amazon Location Service 主控台。

1. 在左側導覽窗格中，選擇**追蹤器**。

1. 在**裝置追蹤器**下，選取目標追蹤器的名稱連結。

1. 在**連結的地理圍欄集合**下，選擇**連結地理圍欄集合**。

1. 在**連結的地理圍欄集合**視窗中，從下拉式功能表中選取地理圍欄集合。

1. 選擇 **Link (連結)**。

連結追蹤器資源後，會為其指派**作用中**狀態。

------
#### [ API ]

**使用 Amazon Location APIs 將追蹤器資源連結至地理圍欄集合**

從 Amazon Location Trackers APIs使用 `[AsssociateTrackerConsumer](https://docs.aws.amazon.com/location-trackers/latest/APIReference/API_AssociateTrackerConsumer.html)`操作。

下列範例使用 API 請求，該請求使用其 [Amazon Resource Name ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html)(ARN) 將 *ExampleTracker* 與地理圍欄集合建立關聯。

```
POST /tracking/v0/trackers/ExampleTracker/consumers
Content-type: application/json

{
   "ConsumerArn": "arn:aws:geo:us-west-2:123456789012:geofence-collection/ExampleGeofenceCollection"
}
```

------
#### [ AWS CLI ]

**使用 AWS CLI 命令將追蹤器資源連結至地理圍欄集合**

使用 `[associate-tracker-consumer](https://docs.aws.amazon.com/cli/latest/reference/location/associate-tracker-consumer.html)` 命令。

下列範例使用 AWS CLI 建立名為 *ExampleGeofenceCollection* 的地理圍欄集合。

```
aws location \
    associate-tracker-consumer \
        --consumer-arn "arn:aws:geo:us-west-2:123456789012:geofence-collection/ExampleGeofenceCollection" \
        --tracker-name "ExampleTracker"
```

------