Query Autocomplete(従来版)を使用すると、入力時に候補のクエリを返すことで、テキストベースの地理的検索のクエリ予測 を提供できます。
Query Autocomplete(従来版)リクエスト
Query Autocomplete(従来版)は Places API(従来版)の一部であり、 Places API(従来版)と API キーと割り当てを共有します。
Query Autocomplete(従来版)を使用すると、アプリケーションにリアルタイムの地理的 クエリ予測を追加できます。ユーザーは特定の 場所を検索する代わりに、「ニューヨークの近くの ピザ屋」などのカテゴリ検索を入力すると、サービスは文字列に一致する候補のクエリのリストを 返します。Query Autocomplete(従来版)は完全な 単語と部分文字列の両方に一致させることができるため、アプリケーションはユーザーの入力に合わせてクエリを送信し、 リアルタイムで予測を提供できます。
Query Autocomplete(以前の)リクエストは、次の形式の HTTP URL です。
https://maps.googleapis.com/maps/api/place/queryautocomplete/output?parameters
ここで、output は json または
xml のいずれかになります。
Query Autocomplete(従来版)リクエストを開始するには、特定のパラメータが必要です。
URL の標準規則と同様に、すべてのパラメータはアンパサンド
(&)文字を使用して区切ります。パラメータとその有効な
値のリストを以下に示します。
必須パラメータ
-
入力
検索するテキスト文字列。Place Autocomplete サービスはこの文字列と一致する候補を、関連性の高い順に並べて結果として返します。
オプション パラメータ
-
language
結果を返す言語。
- サポートされている言語の 一覧をご覧ください。サポート対象の言語は頻繁に更新されるため、このリストで網羅されていない場合があります。
-
languageが指定されていない場合、API はAccept-Languageヘッダーで指定された優先言語を使用しようとします。 - API は、ユーザーと地域住民の両方が読める住所を提供できるよう最善を尽くします。そのために、優先言語を遵守し、必要に応じて、ユーザーが読めるスクリプトに音訳された番地を現地の言語で返します。その他の 住所はすべて優先言語で返されます。住所の構成要素は すべて同じ言語で返されます。この言語は最初の 構成要素から選択されます。
- 優先言語で名前が使用できない場合、API は最も近い一致を使用します。
- 優先言語は、API が返す結果のセットと、結果が返される順序にわずかな影響を与えます。ジオコーダは、言語によって略語の解釈が異なります。たとえば、通りの種類の略語や、ある言語では有効でも別の言語では有効でない同義語などです。たとえば、ハンガリー語では、utcaと térは通りの同義語です。
-
ロケーション
検索する中心となる点を
latitude,longitude座標で定義します。 プレイス サービスは、このロケーションを使用して検索にバイアスをかけ、locationとradiusで定義された範囲内の結果を優先的に表示します。指定した範囲外の結果が返されることもあります。locationパラメータは、queryにMarket in Barcelonaなどの明示的なロケーションが含まれている場合、オーバーライドされることがあります。クエリを引用符で囲むと、locationとradiusに与えられる重みに影響する可能性もあります。 -
offset
サービスが予測の一致に使用する最後の文字の、入力語句内の位置。たとえば、入力が
Googleでオフセットが 3 の場合、サービスはGooに一致します。オフセットによって決定される文字列は、 入力語句の最初の単語とのみ照合されます。たとえば、入力語句がGoogle abcでオフセットが 3 の場合、サービスはGoo abcとの一致を試みます。オフセットが指定されていない場合、サービスは語句全体を使用します。通常、オフセットは テキスト カーソルの位置に設定する必要があります。 -
半径
プレイスの結果を返す範囲の距離(メートル)を定義します。
locationパラメータとradiusパラメータを渡すことで、バイアスを設定し、指定した円の範囲内の結果を優先します。これにより、プレイス サービスが指定した範囲内を優先するように検索結果を絞り込むことができますが、指定した範囲外の結果が返されることもあります。半径は、検索の種類やその他のパラメータに応じて、自動的に最大値にクランプされます。
- 予測入力: 50,000 メートル
-
Nearby Search:
keywordまたはnameを使用する場合: 50,000 メートル-
-
最大 50,000 メートル。地域の密度に基づいて動的に調整されます。
rankbyパラメータとは無関係です。 -
rankby=distanceを使用する場合、radius パラメータは受け入れられず、INVALID_REQUESTが返されます。
keywordまたはnameを使用しない場合 -
最大 50,000 メートル。地域の密度に基づいて動的に調整されます。
- Query Autocomplete: 50,000 メートル
- テキスト検索: 50,000 メートル
Query Autocomplete(従来版)の例
URL
https://maps.googleapis.com/maps/api/place/queryautocomplete/json ?input=pizza%20near%20par &key=YOUR_API_KEY
curl
curl -L -X GET 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=pizza%20near%20par&key=YOUR_API_KEY'「Pizza near Par」というリクエスト(結果はフランス語):
URL
https://maps.googleapis.com/maps/api/place/queryautocomplete/json ?input=pizza%20near%20par &language=fr &key=YOUR_API_KEY
curl
curl -L -X GET 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=pizza%20near%20par&language=fr&key=YOUR_API_KEY'これらの例の API キー は、ご自身のキーに置き換える必要があります。
Query Autocomplete(従来版)のレスポンス
Query Autocomplete(従来版)のレスポンスは、URL リクエストのパス内の output フラグで示される形式で返されます。以下の結果は、次のパラメータを持つクエリに対して返されます。
URL
https://maps.googleapis.com/maps/api/place/queryautocomplete/json ?input=pizza%20near%20par &key=YOUR_API_KEY
curl
curl -L -X GET 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input=pizza%20near%20par&key=YOUR_API_KEY'JSON
{ "predictions": [ { "description": "pizza near Paris, France", "matched_substrings": [{ "length": 5, "offset": 0 }, { "length": 3, "offset": 11 }], "structured_formatting": { "main_text": "pizza", "main_text_matched_substrings": [{ "length": 5, "offset": 0 }], "secondary_text": "near Paris, France", "secondary_text_matched_substrings": [{ "length": 3, "offset": 5 }], }, "terms": [ { "offset": 0, "value": "pizza" }, { "offset": 6, "value": "near" }, { "offset": 11, "value": "Paris" }, { "offset": 18, "value": "France" }, ], }, { "description": "pizza near Pari Chowk, NRI City, Omega II, Noida, Uttar Pradesh, India", "matched_substrings": [{ "length": 5, "offset": 0 }, { "length": 3, "offset": 11 }], "structured_formatting": { "main_text": "pizza", "main_text_matched_substrings": [{ "length": 5, "offset": 0 }], "secondary_text": "near Pari Chowk, NRI City, Omega II, Noida, Uttar Pradesh, India", "secondary_text_matched_substrings": [{ "length": 3, "offset": 5 }], }, "terms": [ { "offset": 0, "value": "pizza" }, { "offset": 6, "value": "near" }, { "offset": 11, "value": "Pari Chowk" }, { "offset": 23, "value": "NRI City" }, { "offset": 33, "value": "Omega II" }, { "offset": 43, "value": "Noida" }, { "offset": 50, "value": "Uttar Pradesh" }, { "offset": 65, "value": "India" }, ], }, { "description": "pizza near Disneyland Park, Disneyland Drive, Anaheim, CA, USA", "matched_substrings": [{ "length": 5, "offset": 0 }, { "length": 3, "offset": 22 }], "structured_formatting": { "main_text": "pizza", "main_text_matched_substrings": [{ "length": 5, "offset": 0 }], "secondary_text": "near Disneyland Park, Disneyland Drive, Anaheim, CA, USA", "secondary_text_matched_substrings": [{ "length": 3, "offset": 16 }], }, "terms": [ { "offset": 0, "value": "pizza" }, { "offset": 6, "value": "near" }, { "offset": 11, "value": "Disneyland Park" }, { "offset": 28, "value": "Disneyland Drive" }, { "offset": 46, "value": "Anaheim" }, { "offset": 55, "value": "CA" }, { "offset": 59, "value": "USA" }, ], }, { "description": "pizza near Cathédrale Notre-Dame de Paris, Parvis Notre-Dame - place Jean-Paul-II, Paris, France", "matched_substrings": [{ "length": 5, "offset": 0 }, { "length": 3, "offset": 36 }], "structured_formatting": { "main_text": "pizza", "main_text_matched_substrings": [{ "length": 5, "offset": 0 }], "secondary_text": "near Cathédrale Notre-Dame de Paris, Parvis Notre-Dame - place Jean-Paul-II, Paris, France", "secondary_text_matched_substrings": [{ "length": 3, "offset": 30 }], }, "terms": [ { "offset": 0, "value": "pizza" }, { "offset": 6, "value": "near" }, { "offset": 11, "value": "Cathédrale Notre-Dame de Paris" }, { "offset": 43, "value": "Parvis Notre-Dame - place Jean-Paul-II" }, { "offset": 83, "value": "Paris" }, { "offset": 90, "value": "France" }, ], }, { "description": "pizza near Paris Beauvais Airport, Route de l'Aéroport, Tillé, France", "matched_substrings": [{ "length": 5, "offset": 0 }, { "length": 3, "offset": 11 }], "structured_formatting": { "main_text": "pizza", "main_text_matched_substrings": [{ "length": 5, "offset": 0 }], "secondary_text": "near Paris Beauvais Airport, Route de l'Aéroport, Tillé, France", "secondary_text_matched_substrings": [{ "length": 3, "offset": 5 }], }, "terms": [ { "offset": 0, "value": "pizza" }, { "offset": 6, "value": "near" }, { "offset": 11, "value": "Paris Beauvais Airport" }, { "offset": 35, "value": "Route de l'Aéroport" }, { "offset": 56, "value": "Tillé" }, { "offset": 63, "value": "France" }, ], }, ], "status": "OK", }
XML
<AutocompletionResponse> <status>OK</status> <prediction> <description>pizza near Paris, France</description> <term> <value>pizza</value> <offset>0</offset> </term> <term> <value>near</value> <offset>6</offset> </term> <term> <value>Paris</value> <offset>11</offset> </term> <term> <value>France</value> <offset>18</offset> </term> <matched_substring> <offset>0</offset> <length>5</length> </matched_substring> <matched_substring> <offset>11</offset> <length>3</length> </matched_substring> <structured_formatting> <description>pizza</description> <subdescription>near Paris, France</subdescription> <description_matched_substring> <offset>0</offset> <length>5</length> </description_matched_substring> <subdescription_matched_substring> <offset>5</offset> <length>3</length> </subdescription_matched_substring> </structured_formatting> </prediction> <prediction> <description>pizza near Pari Chowk, NRI City, Omega II, Noida, Uttar Pradesh, India</description> <term> <value>pizza</value> <offset>0</offset> </term> <term> <value>near</value> <offset>6</offset> </term> <term> <value>Pari Chowk</value> <offset>11</offset> </term> <term> <value>NRI City</value> <offset>23</offset> </term> <term> <value>Omega II</value> <offset>33</offset> </term> <term> <value>Noida</value> <offset>43</offset> </term> <term> <value>Uttar Pradesh</value> <offset>50</offset> </term> <term> <value>India</value> <offset>65</offset> </term> <matched_substring> <offset>0</offset> <length>5</length> </matched_substring> <matched_substring> <offset>11</offset> <length>3</length> </matched_substring> <structured_formatting> <description>pizza</description> <subdescription>near Pari Chowk, NRI City, Omega II, Noida, Uttar Pradesh, India</subdescription> <description_matched_substring> <offset>0</offset> <length>5</length> </description_matched_substring> <subdescription_matched_substring> <offset>5</offset> <length>3</length> </subdescription_matched_substring> </structured_formatting> </prediction> <prediction> <description>pizza near Disneyland Park, Disneyland Drive, Anaheim, CA, USA</description> <term> <value>pizza</value> <offset>0</offset> </term> <term> <value>near</value> <offset>6</offset> </term> <term> <value>Disneyland Park</value> <offset>11</offset> </term> <term> <value>Disneyland Drive</value> <offset>28</offset> </term> <term> <value>Anaheim</value> <offset>46</offset> </term> <term> <value>CA</value> <offset>55</offset> </term> <term> <value>USA</value> <offset>59</offset> </term> <matched_substring> <offset>0</offset> <length>5</length> </matched_substring> <matched_substring> <offset>22</offset> <length>3</length> </matched_substring> <structured_formatting> <description>pizza</description> <subdescription>near Disneyland Park, Disneyland Drive, Anaheim, CA, USA</subdescription> <description_matched_substring> <offset>0</offset> <length>5</length> </description_matched_substring> <subdescription_matched_substring> <offset>16</offset> <length>3</length> </subdescription_matched_substring> </structured_formatting> </prediction> <prediction> <description>pizza near Cathédrale Notre-Dame de Paris, Parvis Notre-Dame - place Jean-Paul-II, Paris, France</description> <term> <value>pizza</value> <offset>0</offset> </term> <term> <value>near</value> <offset>6</offset> </term> <term> <value>Cathédrale Notre-Dame de Paris</value> <offset>11</offset> </term> <term> <value>Parvis Notre-Dame - place Jean-Paul-II</value> <offset>43</offset> </term> <term> <value>Paris</value> <offset>83</offset> </term> <term> <value>France</value> <offset>90</offset> </term> <matched_substring> <offset>0</offset> <length>5</length> </matched_substring> <matched_substring> <offset>36</offset> <length>3</length> </matched_substring> <structured_formatting> <description>pizza</description> <subdescription>near Cathédrale Notre-Dame de Paris, Parvis Notre-Dame - place Jean-Paul-II, Paris, France</subdescription> <description_matched_substring> <offset>0</offset> <length>5</length> </description_matched_substring> <subdescription_matched_substring> <offset>30</offset> <length>3</length> </subdescription_matched_substring> </structured_formatting> </prediction> <prediction> <description>pizza near Paris Beauvais Airport, Route de l'Aéroport, Tillé, France</description> <term> <value>pizza</value> <offset>0</offset> </term> <term> <value>near</value> <offset>6</offset> </term> <term> <value>Paris Beauvais Airport</value> <offset>11</offset> </term> <term> <value>Route de l'Aéroport</value> <offset>35</offset> </term> <term> <value>Tillé</value> <offset>56</offset> </term> <term> <value>France</value> <offset>63</offset> </term> <matched_substring> <offset>0</offset> <length>5</length> </matched_substring> <matched_substring> <offset>11</offset> <length>3</length> </matched_substring> <structured_formatting> <description>pizza</description> <subdescription>near Paris Beauvais Airport, Route de l'Aéroport, Tillé, France</subdescription> <description_matched_substring> <offset>0</offset> <length>5</length> </description_matched_substring> <subdescription_matched_substring> <offset>5</offset> <length>3</length> </subdescription_matched_substring> </structured_formatting> </prediction> </AutocompletionResponse>
プレイス サービスが検索から JSON の結果を返す場合、それらは predictions 配列に配置されます。サービスが結果を返さない場合(location がリモートの場合など)でも、空の predictions 配列が返されます。XML レスポンスは、
0 個以上の <prediction> 要素で構成されます。
PlacesQueryAutocompleteResponse
| フィールド | 必須 | タイプ | 説明 |
|---|---|---|---|
|
required | 配列<PlaceAutocompletePrediction> |
予測の配列が含まれます。 詳細については、 PlaceAutocompletePrediction をご覧ください。 |
|
required | PlacesAutocompleteStatus |
リクエストのステータスが含まれます。リクエストが失敗した原因を追跡できるようにデバッグ情報が格納される場合もあります。 詳細については、PlacesAutocompleteStatus をご覧ください。 |
|
省略可 | 文字列 |
サービスが |
|
省略可 | 配列<文字列> |
サービスがリクエスト仕様に関する追加情報を返す場合、レスポンス オブジェクト内に |
PlacesAutocompleteStatus
サービスによって返されるステータス コード。
OK: API リクエストが成功したことを示します。-
ZERO_RESULTS:検索は成功したが、結果が返されなかったことを示します。これは、検索にリモート ロケーションの境界が渡された場合に発生することがあります。 -
INVALID_REQUEST:API リクエストの形式が正しくないことを示します。通常は、欠落しているinputパラメータが原因です。 -
OVER_QUERY_LIMIT: 次のいずれかを示します。- QPS の上限を超えています。
- アカウントで課金が有効になっていません。
- 月額 $200 のクレジット、またはご自身で設定した使用量の上限を超えています。
- 設定したお支払い方法が無効になっている(クレジット カードの期限切れなど)
-
REQUEST_DENIEDリクエストが拒否されたことを示します。通常、次のいずれかが原因です。- リクエストに API キーがありません。
keyパラメータが無効です。
UNKNOWN_ERROR: 不明なエラーが発生したことを示します。
プレイス サービスが検索から JSON の結果を返す場合、それらは
predictions 配列に配置されます。サービスが結果を返さない場合(location がリモートの場合など)でも、空の predictions 配列が返されます。XML レスポンスは、
0 個以上の <prediction> 要素で構成されます。
PlaceAutocompletePrediction
| フィールド | 必須 | タイプ | 説明 |
|---|---|---|---|
|
required | 文字列 |
返された結果の人が読める形式の名前が含まれます。
|
|
required | 配列<PlaceAutocompleteMatchedSubstring> |
予測結果のテキストに入力された語句の位置を示す部分文字列のリスト。必要に応じて、語句をハイライト表示できます。 詳細については、 PlaceAutocompleteMatchedSubstring をご覧ください。 |
|
required | PlaceAutocompleteStructuredFormat |
予測入力の結果に表示できる事前フォーマット済みのテキストを提供します。このコンテンツはそのまま読み取られます。フォーマット済み住所をプログラムで解析しないでください。 詳細については、 PlaceAutocompleteStructuredFormat をご覧ください。 |
|
required | 配列<PlaceAutocompleteTerm> |
返された説明の各セクションを識別する語句の配列が含まれます(通常、説明のセクションはカンマで区切られます)。配列の各エントリには、語句のテキストを含む
詳細については、PlaceAutocompleteTerm をご覧ください。 |
|
省略可 | integer |
原点からの直線距離(メートル)。このフィールドは
|
|
省略可 | 文字列 |
場所を一意に識別するテキスト表記の ID です。場所に関する情報を取得するには、この ID を Places API リクエストの placeId フィールドに渡します。プレイス ID の詳細については、プレイス ID の概要をご覧ください。 |
|
省略可 | 文字列 |
place_id をご覧ください。 |
|
省略可 | 配列<文字列> |
PlaceAutocompleteMatchedSubstring
| フィールド | 必須 | タイプ | 説明 |
|---|---|---|---|
|
required | 数値 |
予測結果のテキストで一致した部分文字列の長さ。 |
|
required | 数値 |
予測結果のテキストで一致した部分文字列の開始位置。 |
PlaceAutocompleteStructuredFormat
| フィールド | 必須 | タイプ | 説明 |
|---|---|---|---|
|
required | 文字列 |
予測のメインテキスト(通常は場所の名前)が含まれます。 |
|
required | 配列<PlaceAutocompleteMatchedSubstring> |
詳細については、 PlaceAutocompleteMatchedSubstring をご覧ください。 |
|
省略可 | 文字列 |
予測のセカンダリ テキスト(通常は場所のロケーション)が含まれます。 |
|
省略可 | 配列<PlaceAutocompleteMatchedSubstring> |
詳細については、 PlaceAutocompleteMatchedSubstring をご覧ください。 |
PlaceAutocompleteTerm
| フィールド | 必須 | タイプ | 説明 |
|---|---|---|---|
|
required | 数値 |
説明内のこの語句の開始位置を Unicode 文字で定義します。 |
|
required | 文字列 |
語句のテキスト。 |