LoginSignup
1
0

Amazon Location Serviceプレースインデックス機能のフィルター機能を使ってみる

Posted at

Amazon Location Serviceプレースインデックス機能について

Amazon Location Serviceの利用方法や機能については前回の記事で紹介させていただきました。今回はその深掘りで、住所、POIなどの検索におけるフィルター機能を使ってみたいと思います。

フィルター機能

  • BiasPosition:指定された位置に近い場所を優先に返す
  • FilterBBox:指定された境界ボックス内の場所のみを返す
  • FilterCategories:Amazon Location Serviceで設定されたカテゴリのリストと一致する結果を返す
  • MaxResults:返される結果の最大数を指定する

検索してみる

まずはフィルター機能を使わずに住所検索をやってみます。
MaxResultsを5にして、公園を検索してみます。

リクエストURL:POST places.geo.ap-northeast-1.amazonaws.com/places/v0/indexes/インデックス名/search/text?key=Key値
リクエストbody:
{
   "Text": "公園",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "公園",
        "MaxResults": 5,
        "ResultBBox": [
            136.589572785,
            34.975231148,
            143.61268116,
            43.77707725
        ],
        "DataSource": "Esri"
    },
    "Results": [
        {
            "Place": {
                "Label": "北海道北見市留辺蘂町旭公園",
                "Geometry": {
                    "Point": [
                        143.61268116,
                        43.77707725
                    ]
                },
                "Neighborhood": "公園",
                "Region": "北海道",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "NeighborhoodType"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "北海道美唄市峰延町公園",
                "Geometry": {
                    "Point": [
                        141.80992901,
                        43.25619035
                    ]
                },
                "Neighborhood": "公園",
                "Region": "北海道",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "NeighborhoodType"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.589572785,
                        34.975231148
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.626370287,
                        34.980526924
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.622066171,
                        34.994389012
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        }
    ]
}

北海道の公園から三重県の公園、どうしてこの並び順になったのはわかりませんが、この結果に対してフィルタリングをしてみようと思います。

BiasPosition

BiasPositionを東京駅の座標に指定して、リクエストしてみます。

{
   "BiasPosition": [ 139.76721144700002, 35.68118461600005 ],
   "Text": "公園",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "公園",
        "BiasPosition": [
            139.76721144700002,
            35.68118461600005
        ],
        "MaxResults": 5,
        "ResultBBox": [
            139.046212722,
            35.257637386,
            143.61268116,
            43.77707725
        ],
        "DataSource": "Esri"
    },
    "Results": [
        {
            "Place": {
                "Label": "北海道美唄市峰延町公園",
                "Geometry": {
                    "Point": [
                        141.80992901,
                        43.25619035
                    ]
                },
                "Neighborhood": "公園",
                "Region": "北海道",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "NeighborhoodType"
                ]
            },
            "Distance": 861243.7543529939,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "北海道北見市留辺蘂町旭公園",
                "Geometry": {
                    "Point": [
                        143.61268116,
                        43.77707725
                    ]
                },
                "Neighborhood": "公園",
                "Region": "北海道",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "NeighborhoodType"
                ]
            },
            "Distance": 959183.3110081393,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "茨城県坂東市公園",
                "Geometry": {
                    "Point": [
                        139.917124475,
                        36.054105379
                    ]
                },
                "Region": "茨城県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 43660.58639272025,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "神奈川県箱根町公園",
                "Geometry": {
                    "Point": [
                        139.046212722,
                        35.265927097
                    ]
                },
                "Region": "神奈川県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 80057.32198641953,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "神奈川県箱根町公園",
                "Geometry": {
                    "Point": [
                        139.052015481,
                        35.257637386
                    ]
                },
                "Region": "神奈川県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 80170.32955469839,
            "Relevance": 1
        }
    ]
}

レスポンスが変わりました、フィルタリングの効果があったようです。
ただ東京駅周辺の公園ではなかったので、textの部分を英語(公園をpark)に変更してリクエストします。

{
   "BiasPosition": [ 139.76721144700002, 35.68118461600005 ],
   "Text": "park",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "park",
        "BiasPosition": [
            139.76721144700002,
            35.68118461600005
        ],
        "MaxResults": 5,
        "ResultBBox": [
            139.757277336,
            35.678195906,
            139.774724742,
            35.68808914
        ],
        "DataSource": "Esri"
    },
    "Results": [
        {
            "Place": {
                "Label": "東京都千代田区和田倉噴水公園",
                "Geometry": {
                    "Point": [
                        139.760919374,
                        35.683441544
                    ]
                },
                "Region": "東京都",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 621.9385749941764,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "東京都中央区常盤公園",
                "Geometry": {
                    "Point": [
                        139.769983734,
                        35.68808914
                    ]
                },
                "Region": "東京都",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 808.4499758261603,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "東京都千代田区皇居前広場",
                "Geometry": {
                    "Point": [
                        139.758081634,
                        35.678195906
                    ]
                },
                "Region": "東京都",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 890.0709633268135,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "Kokyogaien",
                "Geometry": {
                    "Point": [
                        139.757277336,
                        35.680439882
                    ]
                },
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 902.0844664558233,
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "東京都中央区福徳の森",
                "Geometry": {
                    "Point": [
                        139.774724742,
                        35.687331037
                    ]
                },
                "Region": "東京都",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Distance": 964.1871560489161,
            "Relevance": 1
        }
    ]
}

ちゃんと東京駅周辺の公園を取得することができました!

FilterBBox

FilterBBoxを埼玉県のバウンディングボックス座標に指定して、リクエストしてみます。

{
   "FilterBBox":[138.711382355, 35.753551165, 139.900298388, 36.283558686],
   "Text": "公園",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "公園",
        "FilterBBox": [
            138.711382355,
            35.753551165,
            139.900298388,
            36.283558686
        ],
        "MaxResults": 5,
        "DataSource": "Esri"
    },
    "Results": []
}

結果は何も返されませんでした。検索の仕方を変えて試してみます。
もちろんBiasPositionのように公園をparkにするのは効果があると思います。ここは他の方法も試してみます。
上記のリクエストはSearchPlaceIndexForText機能をベースしたもので、Amazon Location ServiceではSearchPlaceIndexForSuggestions機能もあります。住所や地名に含まれる文字列で検索し、候補を返すことができます。
リクエストURLのtextをsuggestionsに変更し、同じリクエストをしてみます。

リクエストURL:POST places.geo.ap-northeast-1.amazonaws.com/places/v0/indexes/インデックス名/search/suggestions?key=Key値
リクエストbody:
{
   "FilterBBox":[138.711382355, 35.753551165, 139.900298388, 36.283558686],
   "Text": "公園",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "公園",
        "FilterBBox": [
            138.711382355,
            35.753551165,
            139.900298388,
            36.283558686
        ],
        "MaxResults": 5,
        "DataSource": "Esri"
    },
    "Results": [
        {
            "Text": "埼玉県東松山市公園管理事務所",
            "PlaceId": "AQABAKEA7m0r_zQZ-Wda8Gwvqs3woAihrq1L2dR_R7zy6oi0McWgfwmjQPJHYjH9YZhmyxk1SL1OY0OxoiyNypwv3JEmsjDmfNy-AbmnO5mzSQnVQHBZdFOF9aZuPMm6_IL8Sc8bObiLT2F45Nyy969SfRp6QTo0dwM23GVqweCVv4B8Gul8uBcgzzqHiXDMQI2S_0aASm-VTKd7n1KH2pa85ZIGUmY-8yfVAluNF63aH34VX9bzxWZRfr58jACaRiypgXm6_A"
        },
        {
            "Text": "埼玉県比企郡滑川町公園管理センター",
            "PlaceId": "AQABAKEA_ufAC_qfy-8pyMoXeWDKM-r1Lo1d9mHcS_O7M2AyiGiXxFb3cyPTfnfTxIGTqaa0EPgj3QpoYqwPB9JieIPNT2C4_TVZO8CQ0qKeUgKWnU4NCaT4e8za8-AEufNSEuMLDr-MpJqDn3Enx--Bs_onk9ysKgeN31azDgsGXy6_hGjIAzeqYawCaSXPNIvY3YRjFkMvG7Tf9GoTChTLpR_Erg-QdVqb2LkxKqPmFPQ848Lr792IgOb9VVd72dPQw9CsNg"
        },
        {
            "Text": "埼玉県日高市公園管理事務所",
            "PlaceId": "AQABAKEA5Tla7vyYu9o4DDhdAIdYWcb4WQy_jA9S5-tZ8ds4GQTqOCF7GzzIv_vjubn0K20HLHTYbzfQbZvHF4v8SHmHrbkwTpiSL3bM5NUJVeUw7wNAWkwgQxPuX9HYBHjFFki5zb7FWkp5O5fIQWfh0UtaxF3-V3-1DotYN1VSi9wY42qihunmVzk08ntcydlPk6ICXayQt3KrjjjBvGKRNt-Bk4W0PughiGkQaq4N62--axvW1nDOvcyTH7tPSKJhohKaYw"
        },
        {
            "Text": "埼玉県比企郡吉見町公園管理事務所",
            "PlaceId": "AQABAKEAdq4xKEPvKV3vnO5VNPV9ULtUf88jomBdS6QJ-Fk7TaPPmUFhv93a0ZMgZztYzCPPfi9qEmYhzUEZHtm7KwX-82zUqMp-x8QvskQtQonTYWIHUA0lHtsIoLZB4YPlW-TufF0VSl05GafQvtziGKyzg86YvsIPRsbnG8UTbtR8H4YH8H2VOFRU08ygPlE8btRhaYsKT_m6rCez8wxjWqj6HAskG_4-UtlcrtzLBd9ZUsjs0DJvRvPp1Oa_HPfD-NV1rA"
        },
        {
            "Text": "埼玉県熊谷市公園管理事務所",
            "PlaceId": "AQABAKEA01BceoEcHu1xKZFbxiYX_2Cf26mJHUyl5fEprD6B5ZInlk_Hec0QgoS3l4GMXwsEWFGd4a2fLaJOwD9RROUHyRS0fUA4c9T9hhaZvzo9QWtlhzz0XsvBrQvyb89gpJgB-T6w1868jpD-ty6RX0cT5317X_TUgTybMKDnHeJc6zSkCZYnAlP50iFT4xEotGzuJXlYWR_Uag03N1eE1EiIOC9RGWrCwIvJabeK9vIdJQxfdxghW-vwS0sXJlpOIc73Zw"
        }
    ]
}

埼玉県の地名に公園を含めるレスポンス結果が返ってきました。

FilterCategories

Amazon Location Serviceが定義しているカテゴリは以下のドキュメントで確認できます。

FilterCategoriesをparkに指定して、リクエストしてみます。

{
   "FilterCategories":"Park",
   "Text": "公園",
   "MaxResults": 5 
}

レスポンス結果:

{
    "Summary": {
        "Text": "公園",
        "MaxResults": 5,
        "ResultBBox": [
            136.533495256,
            34.975231148,
            136.671262707,
            35.060778725
        ],
        "DataSource": "Esri",
        "FilterCategories": [
            "Park"
        ]
    },
    "Results": [
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.589572785,
                        34.975231148
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.626370287,
                        34.980526924
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.622066171,
                        34.994389012
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県四日市市公園",
                "Geometry": {
                    "Point": [
                        136.671262707,
                        35.007930859
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        },
        {
            "Place": {
                "Label": "三重県菰野町公園",
                "Geometry": {
                    "Point": [
                        136.533495256,
                        35.060778725
                    ]
                },
                "Region": "三重県",
                "Country": "JPN",
                "Interpolated": false,
                "Categories": [
                    "PointOfInterestType",
                    "Park"
                ]
            },
            "Relevance": 1
        }
    ]
}

フィルタリング前の検索結果と比べると、北海道関連のレスポンスはカテゴリがNeighborhoodTypeで、parkとして分類されなかったので、フィルタリングされましたね。

まとめ

Amazon Location Serviceの住所検索に使うフィルター機能を試してみました、ほしい機能が一通り揃っている印象でした。
日本語の検索についてはうまくいかない場合はありますが、その辺の情報を知ってる方があれば是非教えてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0