Method: places.searchText

根據文字查詢搜尋地點。

HTTP 要求

POST https://places.googleapis.com/v1/places:searchText

這個網址使用 gRPC 轉碼語法。

要求主體

要求主體會包含結構如下的資料:

JSON 表示法
{
  "textQuery": string,
  "languageCode": string,
  "regionCode": string,
  "rankPreference": enum (RankPreference),
  "includedType": string,
  "openNow": boolean,
  "minRating": number,
  "maxResultCount": integer,
  "pageSize": integer,
  "pageToken": string,
  "priceLevels": [
    enum (PriceLevel)
  ],
  "strictTypeFiltering": boolean,
  "locationBias": {
    object (LocationBias)
  },
  "locationRestriction": {
    object (LocationRestriction)
  },
  "evOptions": {
    object (EVOptions)
  },
  "routingParameters": {
    object (RoutingParameters)
  },
  "searchAlongRouteParameters": {
    object (SearchAlongRouteParameters)
  },
  "includePureServiceAreaBusinesses": boolean,
  "includeFutureOpeningBusinesses": boolean
}
欄位
textQuery

string

必填。Text Search 的文字查詢。

languageCode

string

系統會盡可能以偏好語言顯示地點詳細資料。如果未指定或無法辨識語言代碼,系統可能會傳回任何語言的地點詳細資料,並優先傳回英文 (如有)。

目前支援的語言清單:https://developers.google.com/maps/faq#languagesupport。

regionCode

string

要求來源位置的 Unicode 國家/地區代碼 (CLDR)。這個參數用於顯示 Place Details,例如特定區域的地點名稱 (如有)。這項參數可能會根據適用法律影響結果。

詳情請參閱 https://www.unicode.org/cldr/charts/latest/supplemental/territory_language_information.html。

請注意,目前不支援 3 位數的區域代碼。

rankPreference

enum (RankPreference)

回應中結果的排序方式。

includedType

string

要求的地點類型。如需支援類型的完整清單,請前往 https://developers.google.com/maps/documentation/places/web-service/place-types。僅支援一個納入類型。

openNow

boolean

用於將搜尋範圍限制在目前營業中的地點。預設值為 false。

minRating

number

篩除平均使用者評分低於此限制的結果。有效值必須是介於 0 至 5 (含) 之間的浮點數,且間隔為 0.5,也就是 [0, 0.5, 1.0, ... , 5.0] (含)。輸入的評分會無條件進位至最接近的 0.5。舉例來說,如果評分為 0.6,系統會排除所有評分低於 1.0 的結果。

maxResultCount
(deprecated)

integer

已淘汰:請改用 pageSize。

每頁可傳回的結果數量上限。如果可用的結果數量大於 maxResultCount,系統會傳回 nextPageToken,並可傳遞至 pageToken,以便在後續要求中取得下一頁結果。如果提供 0 或未提供值,則會使用預設值 20。許可的最大值為 20;超出的數值將一律指定為 20。負值會傳回 INVALID_ARGUMENT 錯誤。

如果同時指定 maxResultCount 和 pageSize,系統會忽略 maxResultCount。

pageSize

integer

(選用步驟) 每頁可傳回的結果數量上限。如果可用的結果數量大於 pageSize,系統會傳回 nextPageToken,並可傳遞至 pageToken,以便在後續要求中取得下一頁結果。如果提供 0 或未提供值,則會使用預設值 20。最大值為 20,超過 20 的值會設為 20。負值會傳回 INVALID_ARGUMENT 錯誤。

如果同時指定 maxResultCount 和 pageSize,系統會忽略 maxResultCount。

pageToken

string

(選用步驟) 屬於接收自前一個 TextSearch 呼叫的網頁權杖。提供此項目即可擷取後續網頁。

進行分頁時,提供給 TextSearch 的所有參數 (pageToken、pageSize 和 maxResultCount 除外),都必須與提供網頁權杖的初始呼叫相符。否則會傳回 INVALID_ARGUMENT 錯誤。

priceLevels[]

enum (PriceLevel)

用於將搜尋範圍限制在標示為特定價格等級的地點。使用者可以選擇任何價格等級組合。預設會選取所有價格等級。

strictTypeFiltering

boolean

用於為 includedType 設定嚴格的類型篩選。如果設為 True,系統只會傳回相同類型的結果。預設為 false。

locationBias

object (LocationBias)

要搜尋的區域。這個位置會做為偏好設定,也就是說,系統可能會傳回指定位置附近的結果。無法與 locationRestriction 一起設定。

locationRestriction

object (LocationRestriction)

要搜尋的區域。這個位置會做為限制,也就是說,系統不會傳回指定位置以外的結果。無法與 locationBias 一起設定。

evOptions

object (EVOptions)

(選用步驟) 設定地點搜尋要求的可搜尋電動車選項。

routingParameters

object (RoutingParameters)

(選用步驟) 用於轉送至結果的其他參數。

searchAlongRouteParameters

object (SearchAlongRouteParameters)

(選用步驟) 沿路線搜尋的其他參數 proto。

includePureServiceAreaBusinesses

boolean

(選用步驟) 如果欄位設為 true,則納入完全無店面區域商家。純無店面區域商家會直接配送或造訪顧客,但不在公司地址為顧客提供服務。例如清潔或水電服務。這類商家在 Google 地圖上沒有實體地址或地點。Places 不會傳回這些商家的 location、plusCode 和其他位置相關欄位。

includeFutureOpeningBusinesses

boolean

(選用步驟) 如果設為 true,則會納入尚未營業但未來會營業的商家。

回應主體

places.searchText 的回應 Proto。

如果成功,回應主體會含有以下結構的資料:

JSON 表示法
{
  "places": [
    {
      object (Place)
    }
  ],
  "routingSummaries": [
    {
      object (RoutingSummary)
    }
  ],
  "contextualContents": [
    {
      object (ContextualContent)
    }
  ],
  "nextPageToken": string,
  "searchUri": string
}
欄位
places[]

object (Place)

符合使用者文字搜尋條件的地點清單。

routingSummaries[]

object (RoutingSummary)

路徑摘要清單,其中每個項目都會與 places 欄位中相同索引的對應地點建立關聯。如果無法提供某個地點的路線摘要,則會包含空白項目。如果提出要求,這份清單的項目數量會與地點清單相同。

contextualContents[]

object (ContextualContent)

實驗功能:詳情請參閱 https://developers.google.com/maps/documentation/places/web-service/experimental/places-generative。

情境內容清單,其中每個項目都會與 places 欄位中相同索引的對應地點建立關聯。系統會優先顯示與要求中 textQuery 相關的內容。如果某個地點沒有情境內容,系統會傳回非情境內容。只有在該地點沒有內容時,才會顯示空白。如果提出要求,這份清單的項目數量會與地點清單相同。

nextPageToken

string

可做為 pageToken 傳送的權杖,用於擷取後續網頁。如果省略這個欄位或留空,就不會有後續頁面。

searchUri

string

使用者可以透過連結,在 Google 地圖上使用與要求中指定的相同文字查詢進行搜尋。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/maps-platform.places.textsearch
  • https://www.googleapis.com/auth/maps-platform.places
  • https://www.googleapis.com/auth/cloud-platform

RankPreference

回應中結果的排序方式。

列舉
RANK_PREFERENCE_UNSPECIFIED 如果是「紐約市的餐廳」這類類別查詢,預設值為 RELEVANCE。如果是「Mountain View, CA」等非類別查詢,建議不要設定 rankPreference。
DISTANCE 依距離排序結果。
RELEVANCE 依關聯性排序結果。排列順序由一般排名堆疊決定。

LocationBias

要搜尋的區域。這個位置會做為偏好設定,也就是說,系統可能會傳回指定位置附近的結果。

JSON 表示法
{

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "rectangle": {
    object (Viewport)
  },
  "circle": {
    object (Circle)
  }
  // End of mutually exclusive fields.
}
欄位
以下是互斥欄位清單。回應中最多會設定下列其中一個欄位:
rectangle

object (Viewport)

由東北角和西南角定義的矩形框。rectangle.high() 必須是矩形可視區域的東北點。rectangle.low() 必須是矩形可視區域的西南點。rectangle.low().latitude()不得大於rectangle.high().latitude()。這會導致緯度範圍空白。矩形可視區域的寬度不得超過 180 度。

circle

object (Circle)

由中心點和半徑定義的圓形。

互斥欄位結束。

LocationRestriction

要搜尋的區域。這個位置會做為限制,也就是說,系統不會傳回指定位置以外的結果。

JSON 表示法
{

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "rectangle": {
    object (Viewport)
  }
  // End of mutually exclusive fields.
}
欄位
以下是互斥欄位清單。回應中最多會設定下列其中一個欄位:
rectangle

object (Viewport)

由東北角和西南角定義的矩形框。rectangle.high() 必須是矩形可視區域的東北點。rectangle.low() 必須是矩形可視區域的西南點。rectangle.low().latitude()不得大於rectangle.high().latitude()。這會導致緯度範圍空白。矩形可視區域的寬度不得超過 180 度。

互斥欄位結束。

EVOptions

地點搜尋要求中可搜尋的電動車選項。

JSON 表示法
{
  "minimumChargingRateKw": number,
  "connectorTypes": [
    enum (EVConnectorType)
  ]
}
欄位
minimumChargingRateKw

number

(選用步驟) 最低充電速率 (單位為千瓦)。系統會篩除充電速率低於指定速率的地點。

connectorTypes[]

enum (EVConnectorType)

(選用步驟) 偏好的電動車充電插頭類型清單。不支援任何所列接頭類型的地點會遭到篩除。

SearchAlongRouteParameters

指定 Routes API 預先計算的折線,定義要搜尋的路徑。沿路線搜尋與使用 locationBias 或 locationRestriction 要求選項來偏重搜尋結果類似。不過,locationBias 和 locationRestriction 選項可讓您指定區域來偏重搜尋結果,而這個選項則可讓您偏重沿著行程路線的結果。

系統不保證結果會沿著提供的路線,而是根據從起點到目的地的最短繞道時間,在折線定義的搜尋區域內排名,並可選擇由 locationBias 或 locationRestriction 定義。結果可能會沿著替代路線顯示,尤其是提供的折線未定義從起點到目的地的最佳路線時。

JSON 表示法
{
  "polyline": {
    object (Polyline)
  }
}
欄位
polyline

object (Polyline)

必填。路線折線。

折線

路線折線。僅支援編碼折線,可做為字串傳遞,並包含壓縮功能,可盡量減少失真。這是 Routes API 的預設輸出內容。

JSON 表示法
{

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "encodedPolyline": string
  // End of mutually exclusive fields.
}
欄位
封裝折線類型。Routes API 輸出內容預設為 encoded_polyline。以下是互斥欄位清單。回應中最多會設定下列其中一個欄位:
encodedPolyline

string

編碼折線:Routes API 預設傳回的格式。請參閱編碼器和解碼器工具。

互斥欄位結束。

ContextualContent

與地點查詢相關的內容。

JSON 表示法
{
  "reviews": [
    {
      object (Review)
    }
  ],
  "photos": [
    {
      object (Photo)
    }
  ],
  "justifications": [
    {
      object (Justification)
    }
  ]
}
欄位
reviews[]

object (Review)

與地點查詢相關的地點評論清單。

photos[]

object (Photo)

這個地點的相片資訊 (包括參考資料),與地點查詢相關。

justifications[]

object (Justification)

地點的理由。

原因

地點的理由。理由可回答使用者為何對某個地點感興趣。

JSON 表示法
{

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "reviewJustification": {
    object (ReviewJustification)
  },
  "businessAvailabilityAttributesJustification": {
    object (BusinessAvailabilityAttributesJustification)
  }
  // End of mutually exclusive fields.
}
欄位
以下是互斥欄位清單。回應中最多會設定下列其中一個欄位:
reviewJustification

object (ReviewJustification)

businessAvailabilityAttributesJustification

object (BusinessAvailabilityAttributesJustification)

互斥欄位結束。

ReviewJustification

使用者評論理由。這會醒目顯示使用者評論中,使用者可能感興趣的部分。舉例來說,如果搜尋查詢是「柴燒披薩」,評論理由就會醒目顯示與搜尋查詢相關的文字。

JSON 表示法
{
  "highlightedText": {
    object (HighlightedText)
  },
  "review": {
    object (Review)
  }
}
欄位
highlightedText

object (HighlightedText)

review

object (Review)

生成醒目顯示文字的評論。

HighlightedText

理由中醒目顯示的文字。這是評論本身的一部分。要醒目顯示的確切字詞會由 HighlightedTextRange 標示。文字中可能有多個字詞會醒目顯示。

JSON 表示法
{
  "text": string,
  "highlightedTextRanges": [
    {
      object (HighlightedTextRange)
    }
  ]
}
欄位
text

string

highlightedTextRanges[]

object (HighlightedTextRange)

醒目顯示文字的範圍清單。

HighlightedTextRange

醒目顯示文字的範圍。

JSON 表示法
{
  "startIndex": integer,
  "endIndex": integer
}
欄位
startIndex

integer

endIndex

integer

BusinessAvailabilityAttributesJustification

BusinessAvailabilityAttributes 理由。這會顯示商家可能吸引使用者的部分屬性。

JSON 表示法
{
  "takeout": boolean,
  "delivery": boolean,
  "dineIn": boolean
}
欄位
takeout

boolean

地點是否提供外帶服務。

delivery

boolean

地點是否提供外送服務。

dineIn

boolean

地點是否提供內用服務。