使用 Amazon Location 新增地理位置 - Amazon Location Service

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

使用 Amazon Location 新增地理位置

Geofences 包含形成封閉界限的點和頂點,定義感興趣區域。Geofence 集合會儲存和管理一個或多個地理。

Amazon Location geofence 集合會儲存使用稱為 GeoJSON (RFC 7946) 的標準地理空間資料格式定義的地理ofence。您可以使用 geojson.io 等工具,以圖形方式繪製地理,並儲存輸出地理JSON檔案。

注意

Amazon Location 不支援多邊形,其中包含跨越非經常性符號的洞、多邊形、順時針多邊形和地理系數。

建立地理集

使用 Amazon Location 主控台、 AWS CLI或 Amazon Location 建立地理集以存放和管理地理APIs。

Console

使用 Amazon Location 主控台建立地理集

  1. 在 開啟 Amazon Location Service 主控台https://console.aws.amazon.com/location/

  2. 在左側導覽窗格中,選擇 Geofence 集合

  3. 選擇建立地理集

  4. 填寫下列方塊:

    • 名稱 – 輸入唯一名稱。例如 ExampleGeofenceCollection。 最多 100 個字元。有效項目包括英數字元、連字號、句點和底線。

    • 描述 – 輸入選用描述,以區分您的資源。

  5. 在將 EventBridge CloudWatch 作為目標 的規則下,您可以建立選用 EventBridge 規則,以開始對地理事件做出反應。這可讓 Amazon Location 將事件發佈至 Amazon CloudWatch Logs。

  6. (選用) 在 Tags (標籤) 底下,輸入標籤 Key (金鑰)Value (值)。這會新增標籤您的新地理圍欄集合。如需詳細資訊,請參閱標記您的 Amazon Location Service 資源

  7. (選用) 在 客戶受管金鑰加密 下,您可以選擇新增客戶受管金鑰 。這會新增對稱客戶受管金鑰,您可以透過預設 AWS 擁有的加密來建立、擁有和管理。如需詳細資訊,請參閱加密靜態資料。

  8. 選擇建立地理集

API

使用 Amazon Location 建立地理集 APIs

使用 Amazon Location Geofences 中的 CreateGeofenceCollection操作APIs。

下列範例使用 API請求來建立名為 的地理集 ExampleGeofenceCollection。 地理位置集合與客戶受管 AWS KMS 金鑰相關聯,以加密客戶資料

POST /geofencing/v0/collections Content-type: application/json { "CollectionName": "ExampleGeofenceCollection", "Description": "Geofence collection 1 for shopping center", "KmsKeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "Tags": { "Tag1" : "Value1" } }
AWS CLI

使用 AWS CLI 命令建立地理集

使用 create-geofence-collection 命令。

下列範例使用 AWS CLI 建立名為 的地理集 ExampleGeofenceCollection。 地理位置集合與客戶受管 AWS KMS 金鑰相關聯,以加密客戶資料

aws location \ create-geofence-collection \ --collection-name "ExampleGeofenceCollection" \ --description "Shopping center geofence collection" \ --kms-key-id "1234abcd-12ab-34cd-56ef-1234567890ab" \ --tags Tag1=Value1
注意

帳單取決於您的用量。使用其他服務 AWS 可能會產生費用。如需詳細資訊,請參閱 Amazon Location Service 定價

繪製地理

現在您已建立地理集,您可以定義地理集。Geofences 定義為多邊形或圓形。若要繪製多邊形地理圍欄,您可以使用地理JSON編輯工具,例如 geojson.io

若要建立地理作為圓,您必須定義圓的中心點和半徑。例如,如果您想要建立地理資訊,以便在裝置位於特定位置 50 公尺內時收到通知,您可以使用該位置的緯度和經度,並將半徑指定為 50 公尺。

您也可以使用 Amazon Location Service APIs,以鍵值對的形式將中繼資料新增至您的地理位置。這些可用於儲存有關地理的資訊,例如其類型,或應用程式特有的其他資訊。您可以在 時使用此中繼資料使用 Amazon 對 Amazon 定 Location Service 事件做出反應 EventBridge

新增多邊形地理ofence

本節說明建立多邊形地理ofences

使用 GeoJSON 工具繪製地理

現在您已建立地理集,您可以使用地理JSON編輯工具定義地理集,例如 geojson.io

建立 GeoJSON 檔案

  1. 開啟地理JSON編輯工具。例如,geojson.io。

  2. 選擇繪製多邊形圖示並繪製您的感興趣區域。

  3. 選擇儲存 ,然後從下拉式選單中選擇地理JSON

將地理JSON地理圍欄放入地理圍欄集合

您可以使用產生的 GeoJSON 檔案,使用 Amazon Location Service 主控台、 AWS CLI或 Amazon Location APIs上傳您的地理:

Console

使用 Amazon Location Service 主控台將地理圍欄新增至地理圍欄集合

  1. 在 開啟 Amazon Location Service 主控台https://console.aws.amazon.com/location/

  2. 在左側導覽窗格中,選擇 Geofence 集合

  3. Geofence 集合清單中,選取目標地理集的名稱連結。

  4. 地理圍欄 下,選擇建立地理圍欄

  5. 新增地理位置視窗中,將您的地理位置JSON拖放到視窗中。

  6. 選擇新增地理位置

API

使用 Amazon Location 新增地理位置 APIs

使用 Amazon Location Geofences 中的 PutGeofence操作APIs。

下列範例使用 API請求來新增指定 ID 的地理位置 GEOFENCE-EXAMPLE1 到名為 的地理集合 ExampleGeofenceCollection。 它也會指定具有索引鍵Type和值 的單一地理中繼資料屬性loadingArea

PUT /geofencing/v0/collections/ExampleGeofenceCollection/geofence/GEOFENCE-EXAMPLE1 Content-type: application/json { "GeofenceProperties": { "Type" : "loadingArea" }, "Geometry": { "Polygon": [ [ [-5.716667, -15.933333], [-14.416667, -7.933333], [-12.316667, -37.066667], [-5.716667, -15.933333] ] ] } }

或者,您可以使用 BatchPutGeofence操作新增多個地理。

POST /geofencing/v0/collections/ExampleGeofenceCollection/put-geofences Content-type: application/json { "Entries": [ { "GeofenceProperties": { "Type" : "loadingArea" }, "GeofenceId": "GEOFENCE-EXAMPLE1", "Geometry": { "Polygon": [ [ [-5.716667, -15.933333], [-14.416667, -7.933333], [-12.316667, -37.066667], [-5.716667, -15.933333] ] ] } } ] }
AWS CLI

使用 AWS CLI 命令將地理圍欄新增至地理圍欄集合

使用 put-geofence 命令。

下列範例使用 AWS CLI 將地理圍欄新增至名為 的地理圍欄集合 ExampleGeofenceCollection.

$ aws location \ put-geofence \ --collection-name ExampleGeofenceCollection \ --geofence-id ExampleGeofenceTriangle \ --geofence-properties '{"Type": "loadingArea"}' \ --geometry 'Polygon=[[[-5.716667, -15.933333],[-14.416667, -7.933333],[-12.316667, -37.066667],[-5.716667, -15.933333]]]' { "CreateTime": "2020-11-11T00:16:14.487000+00:00", "GeofenceId": "ExampleGeofenceTriangle", "UpdateTime": "2020-11-11T00:19:59.894000+00:00" }

新增循環地理

本節說明建立循環地理。您必須知道您想要成為圓中心的點的緯度和經度,以及圓的半徑。您可以使用 Amazon Location APIs或 建立循環地理。 AWS CLI

API

使用 Amazon Location 新增循環地理 APIs

使用 Amazon Location Geofences 中的 PutGeofence操作APIs。

下列範例使用 API請求來新增指定 ID 的地理位置 GEOFENCE-EXAMPLE2 到名為 的地理集合 ExampleGeofenceCollection:

PUT /geofencing/v0/collections/ExampleGeofenceCollection/geofence/GEOFENCE-EXAMPLE2 Content-type: application/json { "Geometry": { "Circle": { "Center": [-5.716667, -15.933333], "Radius": 50 } } }
AWS CLI

使用 AWS CLI 命令將循環地理圍欄新增至地理圍欄集合

使用 put-geofence 命令。

下列範例使用 AWS CLI 將地理圍欄新增至名為 的地理圍欄集合 ExampleGeofenceCollection.

$ aws location \ put-geofence \ --collection-name ExampleGeofenceCollection \ --geofence-id ExampleGeofenceCircle \ --geometry 'Circle={Center=[-5.716667, -15.933333], Radius=50}'
注意

您也可以將JSON複雜幾何設為自己的檔案,如下列範例所示。

$ aws location \ put-geofence \ --collection-name ExampleGeofenceCollection \ --geofence-id ExampleGeofenceCircle \ --geometry file:circle.json

在範例中,circle.json 檔案包含JSON用於圓形幾何的 。

{ "Circle": { "Center": [-74.006975, 40.717127], "Radius": 287.7897969218057 } }