如何使用筛选条件进行地理编码 - Amazon Location Service

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

如何使用筛选条件进行地理编码

地理编码 API 允许您使用筛选条件获取所需结果。

潜在用途

使用筛选条件,根据您的业务需求来限制结果。

示例

IncludeCountries 指定一个值,以在结果中返回该国家/地区的值。

Sample request

如果不使用 IncludeCountries": ["USA"],地理编码 API 将返回加拿大不列颠哥伦比亚省温哥华市。

{ "QueryText": "Vancouver", "Filter" : { "IncludeCountries": ["USA"] } }
Sample response
{ "ResultItems": [ { "PlaceId": "<Redacted>", "PlaceType": "Locality", "Title": "Vancouver, WA, United States", "Address": { "Label": "Vancouver, WA, United States", "Country": { "Code2": "US", "Code3": "USA", "Name": "United States" }, "Region": { "Code": "WA", "Name": "Washington" }, "SubRegion": { "Name": "Clark" }, "Locality": "Vancouver", "PostalCode": "98660" }, "Position": [ -122.67156, 45.63248 ], "MapView": [ -122.77466, 45.57714, -122.46451, 45.69803 ], "MatchScores": { "Overall": 1, "Components": { "Address": { "Locality": 1 } } } } ] }
cURL
curl --request POST \ --url 'https://places.geo.eu-central-1.amazonaws.com/v2/geocode?key=Your_Key' \ --header 'Content-Type: application/json' \ --data '{ "QueryText": "Vancouver", "Filter" : { "IncludeCountries": ["USA"] } }'
AWS CLI
aws geo-places geocode --key ${YourKey} --query-text "Vancouver" --filter '{"IncludeCountries": ["USA"]}'

IncludePlaceTypes 指定一个值,以在结果中返回该地点的值。

Sample request

如果不使用 IncludePlaceTypes": ["Street"],地理编码 API 将返回格鲁吉亚(一个国家)。您可以通过在 "IncludeCountries" 中添加 CANUSA 的值来进一步优化结果,并将结果进行比较。

{ "QueryText": "Georgia", "Filter" : { "IncludePlaceTypes": ["Street"] } }
Sample response
{ "ResultItems": [ { "PlaceId": "<Redacted>", "PlaceType": "Street", "Title": "Georgia, Benito Juárez, CDMX, México", "Address": { "Label": "Georgia, Benito Juárez, CDMX, México", "Country": { "Code2": "MX", "Code3": "MEX", "Name": "México" }, "Region": { "Code": "CDMX", "Name": "Ciudad de México" }, "SubRegion": { "Name": "Ciudad de México" }, "Locality": "Benito Juárez", "Street": "Georgia", "StreetComponents": [ { "BaseName": "Georgia", "Language": "es" } ] }, "Position": [ -99.17754, 19.38887 ], "MapView": [ -99.18133, 19.38755, -99.17374, 19.39016 ], "MatchScores": { "Overall": 1, "Components": { "Address": { "Intersection": [ 1 ] } } } } ] }
cURL
curl --request POST \ --url 'https://places.geo.eu-central-1.amazonaws.com/v2/geocode?key=Your_Key' \ --header 'Content-Type: application/json' \ --data '{ "QueryText": "Georgia", "Filter" : { "IncludePlaceTypes": ["Street"] } }'
AWS CLI
aws geo-places geocode --key ${YourKey} --query-text "Georgia" --filter '{"IncludePlaceTypes": ["Street"]}'

开发人员提示

对于地址地理编码,请尽量使用完整的地址,或使用带有偏差位置组合(包括国家/地区和地点)的查询组件。要了解更多信息,请参阅如何对地址进行地理编码