Amazon Location Serviceのジオコーディング/逆ジオコーディングで検索結果の言語を指定出来るようになりました

2021.11.29

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

いわさです。

Amazon Location Serviceでは、ジオコーディングと逆ジオコーディングの機能が提供されています。

従来まで、このAPIの結果テキストはパートナーベンダーに完全に依存していましたが、API利用者側から検索結果の優先言語を指定出来るようになりました。

優先言語はIETF言語タグ(BCP47)を指定することで検索結果のテキストの優先言語を指定することが可能になりました。
「優先」言語と言っているのは、必ずしもその言語で取得出来るわけではないからです。

If the language is not specified, or not supported for a particular result, the partner automatically chooses a language for the result.

とされており、指定した言語で結果を取得出来るかはデータプロバイダーが対応しているかどうかになります。
ここでいうパートナーはデータプロバイダーを指しており、本日時点ではEsriとHEREを選択することが可能です。

ちなみに優先言語を指定した場合は検索結果には影響しないと記載があります。
結果の言語のみを変更してくれる想定のようです。
..ただし、後述しますが、私が確認した範囲では検索結果が変わるシーンがありました。

This setting affects the languages used in the results. It does not change which results are returned. If the language is not specified, or not supported for a particular result, the partner automatically chooses a language for the result.

SearchPlaceIndexForText - Amazon Location Service : より引用

本日は、両データプロバイダで優先言語を指定して結果を確認してみました。

プロバイダーごとに検索対象による得意・不得意があると認識しています。本記事の検証は検索パターンや複雑性も多くなく、データプロバイダーの優劣を比較したり・特定プロバイダーの利用を推奨するためのものではありません。

AWS CLIのバージョンアップが必要

はじめに、AWS CLIのバージョンアップが必要です。
今回はsearch-place-index-for-textsearch-place-index-for-position--languageオプションを指定するのですが、AWS CLIのバージョンが1.22.7+ or 2.3.7+である必要があります。

[cloudshell-user@ip-10-0-12-155 ~]$ aws --version
aws-cli/2.2.43 Python/3.8.8 Linux/4.14.248-189.473.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2 prompt/off
[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name explore.place --text "札幌" --max-results 3 --language en

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: --language, en

...

[cloudshell-user@ip-10-0-12-155 ~]$ aws --version
aws-cli/2.4.2 Python/3.8.8 Linux/4.14.248-189.473.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2 prompt/off
[cloudshell-user@ip-10-0-12-155 ~]$

Esri

言語:指定なし

ではまずはEsriから、デフォルトの挙動を確認していきます。
場所に依存している感じですね。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name explore.place --text "札幌" --max-results 3 | jq '.Results[].Place.Label'
"北海道札幌市東区札幌"
"北海道札幌市白石区札幌"
"北海道札幌市豊平区札幌"
[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name explore.place --text "USA" --max-results 3 | jq '.Results[].Place.Label'"USA"
"U S"
"Usa, Arusha, TZA"

言語:en

今度は、同じ検索条件で優先言語だけ英語を指定してみます。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name explore.place --text "札幌" --max-results 3 --language en | jq '.Results[].Place.Label'
"Kindergarten, Higashi, Sapporo, Hokkaido, JPN"
"Sapporo Toll Gate, Shiroishi, Sapporo, Hokkaido, JPN"
"Daycare Center, Toyohira, Sapporo, Hokkaido, JPN"

おお、英語表記になりましたね。

言語:ko

英語以外だとどうでしょうか。
試しに韓国語を指定してみます。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name explore.place --text "札幌" --max-results 3 --language ko | jq '.Results[].Place.Label'
"北海道札幌市東区札幌"
"北海道札幌市白石区札幌"
"北海道札幌市豊平区札"

変換されませんでした。
ドイツ語・フランス語などいくつか指定してみましたが、同じ挙動でした。

場所の対応範囲が日本語と英語で設定されている感じでしょうか。

言語:ja

"USA"で検索し、日本語を優先言語に指定してみます。
先程と検索条件が異なるのでデフォルトの場合と指定した場合と2つ載せます。

[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name explore.place --text "USA" --max-results 3 --language ja | jq '.Results[].Place.Label'
"アメリカ合衆国"
"U S"
"Usa, Arusha, TZA"
[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name explore.place --text "USA" --max-results 3 | jq '.Results[].Place.Label'
"USA"
"U S"
"Usa, Arusha, TZA"

やはり、対応している場所は変換され、対応していない場所はデフォルトの言語になっているようです。
プロバイダー側のデータ次第のようですね。

HERE

HEREでも試してみます。

言語:指定なし

こちらも場所に応じたデフォルト言語で取得されるようです。
ちなみに、当然ですがEsriとは検索結果がかなり異なりますね。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "札幌" --max-results 3 | jq '.Results[].Place.Label'
"北海道札幌市"
"北海道札幌市東区丘珠町札幌飛行場"
"北海道札幌市中央区北1条西4丁目札幌グランド"
[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "USA" --max-results 3 | jq '.Results[].Place.Label'
"United States"

言語:en

英語を指定してみます。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "札幌" --max-results 3 --language en | jq '.Results[].Place.Label'
"Sapporo-shi, Hokkaido, Japan"
"Sapporo Airfield, Okadamacho, Higashi-ku, Sapporo-shi, Hokkaido, Japan"
"Sapporo Grand Hotel, Kita1Jonishi 4-chome, Chuo-ku, Sapporo-shi, Hokkaido, Japan"

こちらも期待どおり英語表記になりました。

言語:ko

韓国語を指定してみます。

[cloudshell-user@ip-10-0-12-155 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "札幌" --max-results 3 --language ko | jq '.Results[].Place.Label'
"일본 홋카이도 삿포로시"
"일본 홋카이도 삿포로시 히가시구 오카다마초 삿포로 비행장"
"일본 홋카이도 삿포로시 주오구 기타1조니시 4 조메삿포"

おお、こちらは変換されました。

言語:ja

おっと、検索結果がそもそも違ってますね。。。

[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "USA" --max-results 3 --language ja | jq '.Results[].Place.Label'
"アメリカ合衆国"
"大分県宇佐市"
"アメリカ領バージン諸島"
[cloudshell-user@ip-10-0-38-122 ~]$ aws location search-place-index-for-text --index-name iwasa.here --text "USA" --max-results 3 --language en | jq '.Results[].Place.Label'
"United States"

ドキュメントでは、検索結果に影響が無いとされていましたが、結果の件数が変わっています。
日本語検索の場合は「宇佐(USA)市」が入っていますね...

このあたりは仕様か不具合か現時点でわからないので、languageパラメータ利用にあたって当面は注意しておいたほうが良さそうです。

まとめ

本日はジオコーディング/逆ジオコーディングで優先言語を指定した場合の挙動を確認してみました。
従来、多言語対応を独自で実装していた場合はこのオプションを使うことで翻訳APIの利用やメンテナンスが不要になる可能性があります。
一方、取得結果はデータプロバイダー側のデータの対応状況に依存するのでその点は理解した上での利用が必要になります。