本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在開始地理編碼、反向地理編碼或搜尋位置之前,請遵循先決條件步驟:
建立位置索引資源
首先在 AWS 帳戶中建立位置索引資源。
當您建立位置索引資源時,您可以從可用於支援地理編碼、反向地理編碼和搜尋的 資料提供者中選擇 :
-
Esri – 如需 Esri 在您感興趣區域中涵蓋範圍的詳細資訊,請參閱 Esri 文件中的 Esri 地理編碼涵蓋範圍
。 -
HERE 技術 – 如需有關 在您的關注區域中HERE涵蓋範圍的詳細資訊,請參閱 HERE 文件中的HERE地理編碼涵蓋
範圍。 -
抓取 – 抓取僅提供東南亞的資料。如需 Grab 涵蓋範圍的詳細資訊,請參閱本指南涵蓋的國家/區域和區域中的 。
您可以使用 Amazon Location Service 主控台、 AWS CLI或 Amazon Location 來執行此操作APIs。
使用 Amazon Location Service 主控台建立位置索引資源
-
在 開啟 Amazon Location Service 主控台https://console.aws.amazon.com/location/
。 -
在左側導覽窗格中,選擇放置索引 。
-
選擇建立位置索引 。
-
填寫下列方塊:
-
名稱 – 輸入位置索引資源的名稱。例如
ExamplePlaceIndex
。 最多 100 個字元。有效項目包括英數字元、連字號、句點和底線。 -
描述 – 輸入選用描述。
-
-
在資料提供者 下,選擇要與位置索引資源搭配使用的可用資料提供者
。 注意
如果您的應用程式正在對業務中使用的資產 (例如送貨車輛或員工) 進行追蹤或路線規劃,則不得使用 Esri 作為地理位置提供者。如需詳細資訊,請參閱 AWS 服務條款
第 82 條。 -
在 資料儲存選項 下,指定您是否想要儲存位置索引資源的搜尋結果。
-
(選用) 在 Tags (標籤) 底下,輸入標籤 Key (金鑰) 與 Value (值)。這會新增標籤您的新位置索引資源。如需詳細資訊,請參閱標記您的資源。
-
選擇建立位置索引 。
注意
帳單取決於您的用量。使用其他服務 AWS 可能會產生費用。如需詳細資訊,請參閱 Amazon Location Service 定價
驗證您的請求
建立位置索引資源並準備好開始在應用程式中建置位置功能後,請選擇驗證請求的方式:
-
若要探索您可以存取 服務的方式,請參閱存取 Amazon Location Service 。
-
如果您有具有匿名使用者的網站,您可能想要使用 API Keys 或 Amazon Cognito 。
範例
下列範例顯示使用 API金鑰進行授權、使用 AWS JavaScript SDK v3
和 Amazon Location JavaScript 驗證協助程式。 import { LocationClient, SearchPlaceIndexForTextCommand } from "@aws-sdk/client-location"; import { withAPIKey } from "@aws/amazon-location-utilities-auth-helper"; const apiKey = "
v1.public.your-api-key-value
"; // API key // Create an authentication helper instance using an API key const authHelper = await withAPIKey(apiKey); const client = new LocationClient({ region: "<region>
", // region containing Cognito pool ...authHelper.getLocationClientConfig(), // Provides configuration required to make requests to Amazon Location }); const input = { IndexName: "ExamplePlaceIndex
", Text: "Anyplace", BiasPosition: [-123.4567, 45.6789] }; const command = new SearchPlaceIndexForTextCommand(input); const response = await client.send(command);