Looking for how to use this in your app?See Frontend Libraries →
ロケーション検索の設定
Amplifyのgeoカテゴリは、アプリで「プレイスインデックス」リソースを使用して、場所、住所、座標で検索できるようにします。
新しいロケーション検索インデックスのセットアップ
amplify/backend.ts
import { defineBackend } from "@aws-amplify/backend";import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";import { CfnMap, CfnPlaceIndex } from "aws-cdk-lib/aws-location";import { auth } from "./auth/resource";import { data } from "./data/resource";
const backend = defineBackend({ auth, data, // additional resources});
const geoStack = backend.createStack("geo-stack");
// create a location services mapconst map = new CfnMap(geoStack, "Map", { mapName: "myMap", description: "Map", configuration: { style: "VectorEsriNavigation", }, pricingPlan: "RequestBasedUsage", tags: [ { key: "name", value: "myMap", }, ],});
// create an IAM policy to allow interacting with geo resourceconst myGeoPolicy = new Policy(geoStack, "GeoPolicy", { policyName: "myGeoPolicy", statements: [ new PolicyStatement({ actions: [ "geo:GetMapTile", "geo:GetMapSprites", "geo:GetMapGlyphs", "geo:GetMapStyleDescriptor", ], resources: [map.attrArn], }), ],});
// apply the policy to the authenticated and unauthenticated rolesbackend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
// create a location services place indexconst myIndex = new CfnPlaceIndex(geoStack, "PlaceIndex", { dataSource: "Here", dataSourceConfiguration: { intendedUse: "SingleUse", }, indexName: "myPlaceIndex", pricingPlan: "RequestBasedUsage", tags: [ { key: "name", value: "myPlaceIndex", }, ],});
// create a policy to allow access to the place indexconst myIndexPolicy = new Policy(geoStack, "IndexPolicy", { policyName: "myIndexPolicy", statements: [ new PolicyStatement({ actions: [ "geo:SearchPlaceIndexForPosition", "geo:SearchPlaceIndexForText", "geo:SearchPlaceIndexForSuggestions", "geo:GetPlace", ], resources: [myIndex.attrArn], }), ],});
// attach the policy to the authenticated and unauthenticated IAM rolesbackend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
// patch the place index resource to the expected output configurationbackend.addOutput({ geo: { aws_region: geoStack.region, maps: { items: { [map.mapName]: { style: "VectorEsriNavigation", }, }, default: map.mapName, }, search_indices: { default: myIndex.indexName, items: [myIndex.indexName], }, },});ロケーション検索インデックスの料金プラン
検索インデックスの料金プランはRequestBasedUsageに設定されます。
料金プランの詳細については、ロケーションサービス料金およびロケーションサービス利用規約(82.5セクション)を確認することをお勧めします。
詳細設定
ロケーション検索インデックスのデータプロバイダーと結果の保存場所をオプションで設定できます。
ロケーション検索データプロバイダー
ジオコーディング、リバースジオコーディング、および検索のソースとしてデータプロバイダーを選択できます。 各プロバイダーは、異なる方法でデータを収集および管理しており、世界のさまざまな地域で異なる専門知識を持つ場合があります。 利用可能な地理空間データのデータプロバイダーが表示されます。データプロバイダーの詳細については、ロケーションサービスドキュメンテーションを参照してください。
ロケーション検索結果の保存場所
検索操作の結果がコーラーによってどのように保存されるかを指定できます。
- SingleUse - 結果が保存されないことを指定します。
- Storage - 結果がキャッシュまたはデータベースに保存できることを指定します。
詳細については、このロケーションサービスドキュメントを参照してください。