検索語句の予測入力(従来版)

欧州経済領域(EEA)のデベロッパー

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 が指定されていない場合、API は Accept-Language ヘッダーで指定された優先言語を使用しようとします。
  • API は、ユーザーと現地の人の両方が読み取れる番地を提供するように最善を尽くします。この目標を達成するために、優先言語を考慮して、必要に応じてユーザーが読める文字に変換された、現地語の住所を返します。その他の住所はすべて、優先言語で返されます。住所コンポーネントはすべて同じ言語で返されます。この言語は、最初のコンポーネントから選択されます。
  • 優先言語で名前が利用できない場合、API は最も近い一致を使用します。
  • 優先言語は、API が返す結果のセットと、それらが返される順序にわずかに影響します。ジオコーダは、言語に応じて略語を異なる方法で解釈します。たとえば、道路の種類を表す略語や、ある言語では有効でも別の言語では有効でない類義語などです。たとえば、utca と tér は、ハンガリー語で「通り」の同義語です。

ロケーション

検索対象の中心となるポイントを latitude,longitude 座標として定義します。プレイス サービスは、この位置情報を使用して、location と radius で定義されたエリア内の結果を優先的に表示するように検索をバイアスします。ただし、定義されたエリア外の結果が表示されることもあります。

query に Market in Barcelona などの明示的なロケーションが含まれている場合、location パラメータはオーバーライドされることがあります。クエリを引用符で囲むと、location と radius に割り当てられる重みにも影響する可能性があります。

offset

サービスが予測の一致に使用する最後の文字の、入力キーワード内の位置。たとえば、入力が Google でオフセットが 3 の場合、サービスは Goo と一致します。オフセットによって決定された文字列は、入力キーワードの最初の単語のみと照合されます。たとえば、入力語句が Google abc で、オフセットが 3 の場合、サービスは Goo abc との照合を試みます。オフセットが指定されていない場合、サービスは期間全体を使用します。通常、オフセットはテキスト キャレットの位置に設定する必要があります。

半径

場所の結果を返す距離(メートル単位)を定義します。location パラメータと radius パラメータを渡すことで、バイアスを設定し、指定した円の範囲内の結果を優先します。これによって、プレイス サービスが指定した範囲内を優先するように検索結果を絞り込むことができますが、指定した範囲外の結果が返されることもあります。

半径は、検索の種類やその他のパラメータに応じて、自動的に最大値に制限されます。

  • 予測入力: 50,000 メートル
  • Nearby Search:
    • keyword または name の場合: 50,000 メートル
    • keyword または name なし
      • 最大 50,000 m。rankby パラメータとは無関係に、エリアの密度に基づいて動的に調整されます。
      • rankby=distance を使用する場合、半径パラメータは受け入れられず、INVALID_REQUEST になります。
  • 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 Array<PlaceAutocompletePrediction>

予測の配列が含まれます。

詳細については、PlaceAutocompletePrediction をご覧ください。

required PlacesAutocompleteStatus

リクエストのステータスが格納されます。リクエストが失敗した原因を追跡できるようにデバッグ情報が格納される場合もあります。

詳細については、PlacesAutocompleteStatus をご覧ください。

省略可 文字列

サービスが OK 以外のステータス コードを返した場合、レスポンス オブジェクト内に error_message フィールドが追加されていることがあります。このフィールドには、指定されたステータス コードの理由に関する詳細情報が含まれます。このフィールドは常に返されるとは限りません。また、その内容は変更される可能性があります。

省略可 Array<string>

サービスがリクエスト仕様に関する追加情報を返す場合、レスポンス オブジェクト内に追加の info_messages フィールドが存在することがあります。このフィールドは、リクエストが成功した場合にのみ返されます。常に返されるとは限りません。また、内容は変更される可能性があります。

PlacesAutocompleteStatus

サービスから返されるステータス コード。

  • OK は、API リクエストが成功したことを示します。
  • ZERO_RESULTS は、検索は成功したものの結果が返されなかったことを示します。これは、遠隔地の境界が検索に渡された場合に発生することがあります。
  • INVALID_REQUEST は、API リクエストの形式が正しくないことを示します。通常は、input パラメータが指定されていないことが原因です。
  • OVER_QUERY_LIMIT。次のいずれかを示します。
    • QPS の上限を超えている。
    • アカウントで課金が有効になっていない。
    • 毎月 200 ドル分のクレジット、またはご自身で設定した使用量の上限を超えている。
    • 設定したお支払い方法が無効になっている(クレジット カードの期限切れなど)
    このエラーを解決する方法の詳細については、Maps に関するよくある質問をご覧ください。
  • REQUEST_DENIED は、リクエストが拒否されたことを示します。一般的には、次の理由が考えられます。
    • リクエストに API キーがありません。
    • key パラメータが無効です。
  • UNKNOWN_ERROR は、不明なエラーが発生したことを示します。

Places サービスは、検索から JSON 形式の結果を返す場合、それらを predictions 配列内に配置します。サービスが結果を返さない場合(location がリモートの場合など)でも、空の predictions 配列が返されます。XML レスポンスは、0 個以上の <prediction> 要素で構成されます。

PlaceAutocompletePrediction

フィールド 必須 タイプ 説明
required 文字列

返された結果の人が読める形式の名前が含まれます。establishment の結果の場合、通常はビジネスの名前です。このコンテンツはそのまま読み取られます。フォーマット済み住所をプログラムで解析しないでください。

required Array<PlaceAutocompleteMatchedSubstring>

予測結果のテキスト内に入力された語句の位置を示す部分文字列のリスト。必要に応じて、語句をハイライト表示できます。

詳細については、PlaceAutocompleteMatchedSubstring をご覧ください。

required PlaceAutocompleteStructuredFormat

予測入力の結果に表示できる、事前フォーマットされたテキストを提供します。このコンテンツはそのまま読み取られます。フォーマット済み住所をプログラムで解析しないでください。

詳細については、PlaceAutocompleteStructuredFormat をご覧ください。

required Array<PlaceAutocompleteTerm>

返された説明の各セクションを識別する用語の配列が含まれます(説明のセクションは通常、カンマで区切られます)。配列の各エントリには、用語のテキストを含む value フィールドと、説明内のこの用語の開始位置を定義する offset フィールド(Unicode 文字で測定)があります。

詳細については、PlaceAutocompleteTerm をご覧ください。

省略可 integer

出発地からの直線距離(メートル単位)。このフィールドは、origin で行われたリクエストに対してのみ返されます。

省略可 文字列

場所を一意に識別するテキスト表記の ID。場所に関する情報を取得するには、この ID を Places API リクエストの placeId フィールドに渡します。プレイス ID について詳しくは、プレイス ID の概要をご覧ください。

省略可 文字列

place_id をご覧ください。

省略可 Array<string>

この場所に適用されるタイプの配列が含まれます。例: [ "political", "locality" ]、[ "establishment", "geocode", "beauty_salon" ]。配列には複数の値を指定できます。詳しくは、場所のタイプをご覧ください。

PlaceAutocompleteMatchedSubstring

フィールド 必須 タイプ 説明
required 数値

予測結果テキスト内の一致した部分文字列の長さ。

required 数値

予測結果テキスト内の一致した部分文字列の開始位置。

PlaceAutocompleteStructuredFormat

フィールド 必須 タイプ 説明
required 文字列

予測のメインテキスト(通常は場所の名前)が含まれます。

required Array<PlaceAutocompleteMatchedSubstring>

offset 値と length を含む配列が含まれます。これらは、予測結果テキスト内に入力された語句の位置を表します。これにより、必要に応じて語句をハイライト表示できます。

詳細については、PlaceAutocompleteMatchedSubstring をご覧ください。

省略可 文字列

予測のサブテキスト(通常は場所の位置)が含まれます。

省略可 Array<PlaceAutocompleteMatchedSubstring>

offset 値と length を含む配列が含まれます。これらは、予測結果テキスト内に入力された語句の位置を表します。これにより、必要に応じて語句をハイライト表示できます。

詳細については、PlaceAutocompleteMatchedSubstring をご覧ください。

PlaceAutocompleteTerm

フィールド 必須 タイプ 説明
required 数値

説明におけるこの用語の開始位置を定義します(Unicode 文字単位)。

required 文字列

用語のテキスト。