BasicPlaceAutocompleteElement 類別
google.maps.places.BasicPlaceAutocompleteElement
class
BasicPlaceAutocompleteElement 是 HTMLElement
子類別,可為 Places Autocomplete API 提供 UI 元件。
自訂元素:
<gmp-basic-place-autocomplete included-primary-types="type1 type2 type3..." included-region-codes="c1 c2 c3..." name="string" origin="lat,lng" requested-language="string" requested-region="string" unit-system="metric"></gmp-basic-place-autocomplete>
這個類別會擴充 HTMLElement
。
這個類別會實作 BasicPlaceAutocompleteElementOptions
。
撥打 const {BasicPlaceAutocompleteElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
BasicPlaceAutocompleteElement |
BasicPlaceAutocompleteElement(options) 參數:
|
屬性 | |
---|---|
includedPrimaryTypes |
類型:
Array<string> optional HTML 屬性:
|
includedRegionCodes |
類型:
Array<string> optional 只納入指定區域的結果,最多可指定 15 個 CLDR 雙字元區域代碼。如果集合為空白,系統不會限制結果。如果同時設定
locationRestriction 和 includedRegionCodes ,結果會位於交集區域。HTML 屬性:
|
locationBias |
類型:
LocationBias optional 搜尋地點時使用的軟性邊界或提示。 |
locationRestriction |
類型:
LocationRestriction optional 用來限制搜尋結果的範圍。 |
name |
類型:
string optional 輸入元素要使用的名稱。詳情請參閱 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name。與輸入內容的名稱屬性行為相同。請注意,提交表單時會使用這個名稱。詳情請參閱 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form。
HTML 屬性:
|
origin |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional 計算距離的起點。如未指定,系統就不會計算距離。系統不會使用海拔高度 (如有) 進行計算。
HTML 屬性:
|
requestedLanguage |
類型:
string optional 盡可能提供語言 ID,指出應以哪種語言傳回結果。系統可能會優先顯示所選語言的結果,但建議不限於該語言。請參閱支援語言清單。
HTML 屬性:
|
requestedRegion |
類型:
string optional 用於格式化和篩選結果的區域代碼。這不會將建議限制在該國家/地區。區碼接受 ccTLD (「頂層網域」) 的兩位字元值。多數 ccTLD 代碼與 ISO 3166-1 代碼相同,只有少數例外。舉例來說,英國的 ccTLD 是「uk」(
.co.uk ),而 ISO 3166-1 代碼是「gb」(技術上是指「大不列顛及北愛爾蘭聯合王國」實體)。HTML 屬性:
|
unitSystem |
類型:
UnitSystem optional 顯示距離時使用的單位制。如未指定,系統會根據 requestedRegion 決定單位系統。
HTML 屬性:
|
運算單元 | |
---|---|
prediction-item-icon |
這個 slot 只能接受一個 <template> 元素,做為預測項目旁顯示的圖示。 |
零件 | |
---|---|
prediction-item |
預測下拉式選單中的項目,代表單一預測。 |
prediction-item-icon |
顯示在預測查詢字串清單中每個項目左側的圖示。 |
prediction-item-main-text |
預測項目的一部分,是預測結果的主要文字。就地理位置而言,這包含地方資訊名稱 (例如「Sydney」) 或街道名稱及門牌號碼 (例如「10 King Street」)。預設情況下,prediction-item-main-text 為黑色。如果預測項目中有任何額外文字,則會位於 prediction-item-main-text 之外,並沿用 prediction-item 的樣式。在預設情況下會以灰色顯示。這組額外文字通常是地址。 |
prediction-item-match |
傳回的預測查詢字串中,與使用者輸入文字相符的部分。根據預設,這組相符文字會以粗體字標示。請注意,相符文字可能會在 prediction-item 內的任何位置,不一定是 prediction-item-main-text 的一部分。 |
prediction-item-selected |
使用者透過鍵盤導覽至的項目。注意:選取的項目會受到這部分樣式和預測項目部分樣式的影響。 |
prediction-list |
包含「地方資訊自動完成」服務所傳回預測查詢字串清單的視覺元素。這份清單會以下拉式選單的形式,顯示在 PlaceAutocompleteElement 下方。 |
CSS 屬性 | |
---|---|
background-color |
覆寫元素的背景顏色。 |
border |
覆寫元素的邊框。 |
border-radius |
覆寫元素的邊框半徑。 |
color-scheme |
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
事件 | |
---|---|
gmp-error |
function(errorEvent) 引數:
當後端要求遭到拒絕時 (例如 API 金鑰不正確),就會觸發這項事件。這個事件不會冒泡。 |
gmp-select |
function(placeSelectEvent) 引數:
使用者選取地點預測時,系統會觸發這項事件。包含 Place 物件。 |
BasicPlaceAutocompleteElementOptions 介面
google.maps.places.BasicPlaceAutocompleteElementOptions
介面
建構 BasicPlaceAutocompleteElement 的選項。
屬性 | |
---|---|
includedPrimaryTypes optional |
類型:
Array<string> optional |
includedRegionCodes optional |
類型:
Array<string> optional |
locationBias optional |
類型:
LocationBias optional |
locationRestriction optional |
類型:
LocationRestriction optional |
name optional |
類型:
string optional |
origin optional |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional |
requestedLanguage optional |
類型:
string optional |
requestedRegion optional |
類型:
string optional |
unitSystem optional |
類型:
UnitSystem optional |
PlaceAutocompleteElement 類別
google.maps.places.PlaceAutocompleteElement
class
PlaceAutocompleteElement 是 HTMLElement
子類別,可為 Places Autocomplete API 提供 UI 元件。
PlaceAutocompleteElement 會在內部自動使用 AutocompleteSessionToken
s,將使用者自動完成搜尋的查詢和選取階段歸入不同的工作階段。
對 PlacePrediction.toPlace
傳回的 Place
進行第一次 Place.fetchFields
呼叫時,系統會自動加入用於擷取 PlacePrediction
的工作階段符記。
如要進一步瞭解工作階段的運作方式,請參閱 https://developers.google.com/maps/documentation/places/web-service/place-session-tokens。
自訂元素:
<gmp-place-autocomplete included-primary-types="type1 type2 type3..." included-region-codes="c1 c2 c3..." name="string" origin="lat,lng" requested-language="string" requested-region="string" unit-system="metric"></gmp-place-autocomplete>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceAutocompleteElementOptions
。
撥打 const {PlaceAutocompleteElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceAutocompleteElement |
PlaceAutocompleteElement(options) 參數:
|
屬性 | |
---|---|
includedPrimaryTypes |
類型:
Array<string> optional HTML 屬性:
|
includedRegionCodes |
類型:
Array<string> optional 只納入指定區域的結果,最多可指定 15 個 CLDR 雙字元區域代碼。如果集合為空白,系統不會限制結果。如果同時設定
locationRestriction 和 includedRegionCodes ,結果會位於交集區域。HTML 屬性:
|
locationBias |
類型:
LocationBias optional 搜尋地點時使用的軟性邊界或提示。 |
locationRestriction |
類型:
LocationRestriction optional 用來限制搜尋結果的範圍。 |
name |
類型:
string optional 輸入元素要使用的名稱。詳情請參閱 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name。與輸入內容的名稱屬性行為相同。請注意,提交表單時會使用這個名稱。詳情請參閱 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form。
HTML 屬性:
|
origin |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional 計算距離的起點。如未指定,系統就不會計算距離。系統不會使用海拔高度 (如有) 進行計算。
HTML 屬性:
|
requestedLanguage |
類型:
string optional 盡可能提供語言 ID,指出應以哪種語言傳回結果。系統可能會優先顯示所選語言的結果,但建議不限於該語言。請參閱支援語言清單。
HTML 屬性:
|
requestedRegion |
類型:
string optional 用於格式化和篩選結果的區域代碼。這不會將建議限制在該國家/地區。區碼接受 ccTLD (「頂層網域」) 的兩位字元值。多數 ccTLD 代碼與 ISO 3166-1 代碼相同,只有少數例外。舉例來說,英國的 ccTLD 是「uk」(
.co.uk ),而 ISO 3166-1 代碼是「gb」(技術上是指「大不列顛及北愛爾蘭聯合王國」實體)。HTML 屬性:
|
unitSystem |
類型:
UnitSystem optional 顯示距離時使用的單位制。如未指定,系統會根據 requestedRegion 決定單位系統。
HTML 屬性:
|
零件 | |
---|---|
prediction-item |
預測下拉式選單中的項目,代表單一預測。 |
prediction-item-icon |
顯示在預測查詢字串清單中每個項目左側的圖示。 |
prediction-item-main-text |
預測項目的一部分,是預測結果的主要文字。就地理位置而言,這包含地方資訊名稱 (例如「Sydney」) 或街道名稱及門牌號碼 (例如「10 King Street」)。預設情況下,prediction-item-main-text 為黑色。如果預測項目中有任何額外文字,則會位於 prediction-item-main-text 之外,並沿用 prediction-item 的樣式。在預設情況下會以灰色顯示。這組額外文字通常是地址。 |
prediction-item-match |
傳回的預測查詢字串中,與使用者輸入文字相符的部分。根據預設,這組相符文字會以粗體字標示。請注意,相符文字可能會在 prediction-item 內的任何位置,不一定是 prediction-item-main-text 的一部分。 |
prediction-item-selected |
使用者透過鍵盤導覽至的項目。注意:選取的項目會受到這部分樣式和預測項目部分樣式的影響。 |
prediction-list |
包含「地方資訊自動完成」服務所傳回預測查詢字串清單的視覺元素。這份清單會以下拉式選單的形式,顯示在 PlaceAutocompleteElement 下方。 |
CSS 屬性 | |
---|---|
background-color |
覆寫元素的背景顏色。 |
border |
覆寫元素的邊框。 |
border-radius |
覆寫元素的邊框半徑。 |
color-scheme |
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
事件 | |
---|---|
gmp-error |
function(errorEvent) 引數:
當後端要求遭到拒絕時 (例如 API 金鑰不正確),就會觸發這項事件。這個事件不會冒泡。 |
gmp-select |
function(placePredictionSelectEvent) 引數:
使用者選取地點預測時,系統會觸發這項事件。內含可轉換為 Place 物件的 PlacePrediction 物件。 |
PlaceAutocompleteElementOptions interface
google.maps.places.PlaceAutocompleteElementOptions
介面
建構 PlaceAutocompleteElement 的選項。如要瞭解各項屬性,請參閱 PlaceAutocompleteElement 類別中同名的屬性。
屬性 | |
---|---|
includedPrimaryTypes optional |
類型:
Array<string> optional |
includedRegionCodes optional |
類型:
Array<string> optional |
locationBias optional |
類型:
LocationBias optional |
locationRestriction optional |
類型:
LocationRestriction optional |
name optional |
類型:
string optional |
origin optional |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional |
requestedLanguage optional |
類型:
string optional |
requestedRegion optional |
類型:
string optional |
unitSystem optional |
類型:
UnitSystem optional |
PlacePredictionSelectEvent class
google.maps.places.PlacePredictionSelectEvent
class
使用者透過 PlaceAutocompleteElement 選取預測項目後,系統就會建立這個事件。使用 event.placePrediction
存取選取範圍。
呼叫 PlacePrediction.toPlace
,將 placePrediction 轉換為 Place
。
這個類別會擴充 Event
。
撥打 const {PlacePredictionSelectEvent} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
屬性 | |
---|---|
placePrediction |
類型:
PlacePrediction 呼叫 PlacePrediction.toPlace 將其轉換為 Place 。 |
PlaceAutocompleteRequestErrorEvent class
google.maps.places.PlaceAutocompleteRequestErrorEvent
class
網路要求發生問題時,PlaceAutocompleteElement 會發出這個事件。
這個類別會擴充 Event
。
撥打 const {PlaceAutocompleteRequestErrorEvent} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
PlaceContextualElement class
google.maps.places.PlaceContextualElement
class
這個小工具會使用情境權杖,顯示 Grounding with Google Maps 回應的情境檢視畫面。
自訂元素:
<gmp-place-contextual context-token="string"></gmp-place-contextual>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceContextualElementOptions
。
撥打 const {PlaceContextualElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceContextualElement |
PlaceContextualElement([options]) 參數:
|
屬性 | |
---|---|
contextToken |
類型:
string optional 內容權杖。
HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceContextualElementOptions interface
google.maps.places.PlaceContextualElementOptions
介面
「PlaceContextualElement
」的選項。
屬性 | |
---|---|
contextToken optional |
類型:
string optional Grounding with Google Maps 回應提供的內容權杖。 |
PlaceContextualListConfigElement class
google.maps.places.PlaceContextualListConfigElement
class
HTML 元素,可設定地點情境元素清單檢視畫面的選項。
自訂元素:
<gmp-place-contextual-list-config layout="compact" map-hidden map-mode="none"></gmp-place-contextual-list-config>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceContextualListConfigElementOptions
。
撥打 const {PlaceContextualListConfigElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceContextualListConfigElement |
PlaceContextualListConfigElement([options]) 參數:
|
屬性 | |
---|---|
layout |
類型:
PlaceContextualListLayout optional 版面配置。
HTML 屬性:
|
mapHidden |
類型:
boolean optional 地圖是否隱藏。
HTML 屬性:
|
mapMode |
類型:
PlaceContextualListMapMode optional 用於地點情境元素的地圖模式,可顯示地點清單。
HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceContextualListConfigElementOptions 介面
google.maps.places.PlaceContextualListConfigElementOptions
介面
PlaceContextualListConfigElement 的選項。
屬性 | |
---|---|
layout optional |
類型:
PlaceContextualListLayout optional 版面配置。 |
mapHidden optional |
類型:
boolean optional 預設值:
false 是否應隱藏地圖。 |
mapMode optional |
類型:
PlaceContextualListMapMode optional 用於地點情境元素的地圖模式,可顯示地點清單。 |
PlaceContextualListLayout 常數
google.maps.places.PlaceContextualListLayout
常數
地點內容元素支援清單檢視畫面的版面配置清單。
撥打 const {PlaceContextualListLayout} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
常數 | |
---|---|
COMPACT |
精簡清單版面配置:清單項目會以單行連結的形式呈現,溢出的項目則會顯示在下拉式清單中。 |
VERTICAL |
直向清單版面配置:清單項目會以直向清單中的資訊卡形式呈現。 |
PlaceContextualListMapMode 常數
google.maps.places.PlaceContextualListMapMode
常數
用於地點情境元素的地圖模式,可顯示地點清單。
撥打 const {PlaceContextualListMapMode} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
常數 | |
---|---|
HYBRID |
衛星圖像或擬真 3D 圖像上的主要街道透明圖層。 |
NONE |
沒有地圖。 |
ROADMAP |
一般的 2D 街道地圖。 |
PlaceDetailsElement class
google.maps.places.PlaceDetailsElement
class
以完整版面配置顯示地點詳細資料。附加 PlaceDetailsPlaceRequestElement
或 PlaceDetailsLocationRequestElement
,指定要顯示的位置。附加 PlaceContentConfigElement
、PlaceStandardContentElement
或 PlaceAllContentElement
,指定要算繪的內容。
示例:
<gmp-place-details>
<gmp-place-details-place-request
place="PLACE_ID"
></gmp-place-details-place-request>
<gmp-place-content-config>
<gmp-place-media lightbox-preferred></gmp-place-media>
</gmp-place-content-config>
</gmp-place-details>
如要使用這個元素,請在 Google Cloud 控制台中為專案啟用 Places UI Kit API。
自訂元素:
<gmp-place-details></gmp-place-details>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceDetailsElementOptions
。
撥打 const {PlaceDetailsElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceDetailsElement |
PlaceDetailsElement([options]) 參數:
|
屬性 | |
---|---|
place |
類型:
Place optional 僅供檢視。Place 物件,內含目前算繪地點的 ID、位置和可視區域。 |
CSS 屬性 | |
---|---|
--gmp-button-border-color |
「在 Google 地圖中開啟」按鈕的框線顏色。 |
--gmp-button-border-radius |
「在地圖中開啟」按鈕的邊框半徑。 |
--gmp-button-border-width |
「在 Google 地圖中開啟」按鈕的邊框寬度。 |
--gmp-collage-border-radius-outer |
媒體拼貼外角的圓角半徑。 |
--gmp-dialog-border-radius |
Google 地圖揭露資訊對話方塊的邊框半徑。 |
--gmp-mat-color-disabled-surface |
表面顏色,用於表示停用狀態或不存在。用於空白的評論星號。 |
--gmp-mat-color-info |
具有資訊情緒的 UI 元素顏色。用於輪椅圖示。 |
--gmp-mat-color-negative |
情緒負面的 UI 元素顏色。用於「現在營業中」狀態的「已關閉」文字。 |
--gmp-mat-color-neutral-container |
中性填滿 UI 元素的容器顏色。用於圖片預留位置和顯示發布日期徽章。 |
--gmp-mat-color-on-neutral-container |
文字和圖示的顏色與中性容器顏色對比。用於顯示評論發布日期徽章,以及電動車充電器供應情形徽章 (如果無法使用)。 |
--gmp-mat-color-on-positive-container |
文字和圖示在正向容器顏色上的呈現效果。如有電動車充電樁供應情形徽章,系統會使用這項資訊。 |
--gmp-mat-color-on-secondary-container |
文字和圖示的顏色,與次要容器顏色形成對比。用於「在 Google 地圖中開啟」按鈕上的文字和圖示。 |
--gmp-mat-color-on-surface |
文字和圖示在任何介面顏色上的顏色。用於一般文字。 |
--gmp-mat-color-on-surface-variant |
在任何介面顏色上,文字和圖示的低強調色。用於較不強調的文字。 |
--gmp-mat-color-outline-decorative |
非互動式元素的外框顏色。用於元素邊框。 |
--gmp-mat-color-positive |
情緒正向的 UI 元素顏色。用於「營業中」狀態中的「營業中」文字。 |
--gmp-mat-color-positive-container |
用於傳達正面情緒的 UI 元素容器顏色。如有電動車充電樁供應情形徽章,系統會使用這項資訊。 |
--gmp-mat-color-primary |
互動式文字和圖示的顏色,與介面顏色形成對比。用於評論數、Google 地圖揭露事項對話方塊中的連結、網站連結、總覽分頁中的圖示,以及分頁列標題的 (懸停 / 焦點 / 文字顏色)。 |
--gmp-mat-color-secondary-container |
相較於表面,填滿顏色較不顯眼,適用於色調按鈕等隱性元件。用於「在 Google 地圖中開啟」按鈕的背景。 |
--gmp-mat-color-surface |
背景顏色。用於元素和 Google 地圖揭露資訊對話方塊的背景。 |
--gmp-mat-font-body-medium |
用於 Google 地圖揭露資訊對話方塊中的地點地址、評分、類型、價格、目前營業狀態、營業時間、評論、電話號碼、網站、加號代碼、熱門功能和內文。 |
--gmp-mat-font-body-small |
用於「關於」分頁中功能清單的內文。 |
--gmp-mat-font-display-small |
用於地點名稱和「關於」分頁中每個功能標題的文字。 |
--gmp-mat-font-family |
用於所有文字的基本字型系列。 |
--gmp-mat-font-headline-medium |
用於 Google 地圖揭露事項對話方塊中的標題文字。 |
--gmp-mat-font-label-large |
用於分頁標題、「在 Google 地圖中開啟」按鈕、相片庫中的評論者出處文字、評論專區中的評論者出處文字,以及 Google 地圖揭露資訊對話方塊中的連結。 |
--gmp-mat-font-label-medium |
用於相片計數徽章和評論發布日期徽章。 |
--gmp-mat-font-title-small |
用於「關於」分頁中各個部分的標題。 |
--gmp-mat-spacing-extra-large |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-extra-small |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-large |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-medium |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-small |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-two-extra-large |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-star-rating-color |
評分中實心星號的顏色。 |
background-color |
覆寫元素的背景顏色。 |
border |
覆寫元素的邊框。 |
border-radius |
覆寫元素的邊框半徑。 |
color-scheme |
|
font-size |
縮放元素中的所有文字和圖示,這些項目在內部是以 em 為單位定義。預設值為 16px 。 |
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
事件 | |
---|---|
gmp-error |
function(event) 引數:
當後端要求遭到拒絕時 (例如 API 金鑰不正確),就會觸發這項事件。這個事件不會冒泡。 |
gmp-load |
function(event) 引數:
當元素載入並算繪內容時,系統會觸發這個事件。這個事件不會冒泡。 |
PlaceDetailsElementOptions interface
google.maps.places.PlaceDetailsElementOptions
介面
「PlaceDetailsElement
」的選項。
PlaceDetailsCompactElement class
google.maps.places.PlaceDetailsCompactElement
class
以精簡版面配置顯示地點詳細資料。附加 PlaceDetailsPlaceRequestElement
或 PlaceDetailsLocationRequestElement
,指定要顯示的地點。附加 PlaceContentConfigElement
、PlaceStandardContentElement
或 PlaceAllContentElement
,指定要算繪的內容。
示例:
<gmp-place-details-compact>
<gmp-place-details-place-request
place="PLACE_ID"
></gmp-place-details-place-request>
<gmp-place-content-config>
<gmp-place-media lightbox-preferred></gmp-place-media>
</gmp-place-content-config>
</gmp-place-details-compact>
如要使用這個元素,請在 Google Cloud 控制台中為專案啟用 Places UI Kit API。
自訂元素:
<gmp-place-details-compact orientation="vertical" truncation-preferred></gmp-place-details-compact>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceDetailsCompactElementOptions
。
撥打 const {PlaceDetailsCompactElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceDetailsCompactElement |
PlaceDetailsCompactElement([options]) 參數:
|
屬性 | |
---|---|
orientation |
類型:
PlaceDetailsOrientation optional 預設值:
PlaceDetailsOrientation.VERTICAL 元素的方向變體 (垂直或水平)。
HTML 屬性:
|
place |
類型:
Place optional 僅供檢視。Place 物件,內含目前算繪地點的 ID、位置和可視區域。 |
truncationPreferred |
類型:
boolean 預設值:
false 如果為 true,系統會截斷地點名稱和地址,以符合單行顯示空間,而不是換行。
HTML 屬性:
|
CSS 屬性 | |
---|---|
--gmp-button-border-color |
「在 Google 地圖中開啟」按鈕的框線顏色。 |
--gmp-button-border-radius |
「在地圖中開啟」按鈕的邊框半徑。 |
--gmp-button-border-width |
「在 Google 地圖中開啟」按鈕的邊框寬度。 |
--gmp-dialog-border-radius |
Google 地圖揭露資訊對話方塊的邊框半徑。 |
--gmp-mat-color-info |
具有資訊情緒的 UI 元素顏色。用於輪椅圖示。 |
--gmp-mat-color-negative |
情緒負面的 UI 元素顏色。用於「現在營業中」狀態的「已關閉」文字。 |
--gmp-mat-color-neutral-container |
中性填滿 UI 元素的容器顏色。用於圖片預留位置。 |
--gmp-mat-color-on-secondary-container |
文字和圖示的顏色,與次要容器顏色形成對比。用於「在 Google 地圖中開啟」按鈕上的文字和圖示。 |
--gmp-mat-color-on-surface |
文字和圖示在任何介面顏色上的顏色。用於一般文字。 |
--gmp-mat-color-on-surface-variant |
在任何介面顏色上,文字和圖示的低強調色。用於較不強調的文字。 |
--gmp-mat-color-outline-decorative |
非互動式元素的外框顏色。用於元素邊框。 |
--gmp-mat-color-positive |
情緒正向的 UI 元素顏色。用於「營業中」狀態中的「營業中」文字。 |
--gmp-mat-color-primary |
互動式文字和圖示的顏色,與介面顏色形成對比。用於評論數,以及 Google 地圖揭露資訊對話方塊中的連結。 |
--gmp-mat-color-secondary-container |
相較於表面,填滿顏色較不顯眼,適用於色調按鈕等隱性元件。用於「在 Google 地圖中開啟」按鈕的背景。 |
--gmp-mat-color-surface |
背景顏色。用於元素和 Google 地圖揭露資訊對話方塊的背景。 |
--gmp-mat-font-body-medium |
用於 Google 地圖揭露事項對話方塊中的內文。 |
--gmp-mat-font-body-small |
用於地點地址、評分、類型、價格和目前營業狀態。 |
--gmp-mat-font-family |
用於所有文字的基本字型系列。 |
--gmp-mat-font-headline-medium |
用於 Google 地圖揭露事項對話方塊中的標題文字。 |
--gmp-mat-font-label-large |
用於「在 Google 地圖中開啟」按鈕,以及 Google 地圖揭露事項對話方塊中的連結,和相片庫中的評論者出處文字。 |
--gmp-mat-font-label-medium |
用於相片計數徽章。 |
--gmp-mat-font-title-small |
用於地點名稱。 |
--gmp-mat-spacing-extra-small |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-large |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-medium |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-mat-spacing-small |
用於元素內的間距,例如文字周圍的邊界和邊框間距。 |
--gmp-star-rating-color |
評分中實心星號的顏色。 |
--gmp-thumbnail-border-radius |
地點縮圖的邊框半徑。 |
background-color |
覆寫元素的背景顏色。 |
border |
覆寫元素的邊框。 |
border-radius |
覆寫元素的邊框半徑。 |
color-scheme |
|
font-size |
縮放元素中的所有文字和圖示,這些項目在內部是以 em 為單位定義。預設值為 16px 。 |
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
事件 | |
---|---|
gmp-error |
function(event) 引數:
當後端要求遭到拒絕時 (例如 API 金鑰不正確),就會觸發這項事件。這個事件不會冒泡。 |
gmp-load |
function(event) 引數:
當元素載入並算繪內容時,系統會觸發這個事件。這個事件不會冒泡。 |
PlaceDetailsCompactElementOptions interface
google.maps.places.PlaceDetailsCompactElementOptions
介面
「PlaceDetailsCompactElement
」的選項。
屬性 | |
---|---|
orientation optional |
類型:
PlaceDetailsOrientation optional |
truncationPreferred optional |
類型:
boolean optional |
PlaceDetailsOrientation 常數
google.maps.places.PlaceDetailsOrientation
常數
「PlaceDetailsCompactElement
」的螢幕方向變體。
撥打 const {PlaceDetailsOrientation} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
常數 | |
---|---|
HORIZONTAL |
橫向。 |
VERTICAL |
直向。 |
PlaceDetailsPlaceRequestElement 類別
google.maps.places.PlaceDetailsPlaceRequestElement
class
設定 PlaceDetailsCompactElement
或 PlaceDetailsElement
,根據地點物件、ID 或資源名稱載入資料。將這個元素附加為 PlaceDetailsCompactElement
或 PlaceDetailsElement
的子項,即可載入指定地點的資料。例如:
<gmp-place-details>
<gmp-place-details-place-request
place="PLACE_ID"
></gmp-place-details-place-request>
</gmp-place-details>
自訂元素:
<gmp-place-details-place-request place="some-place-id"></gmp-place-details-place-request>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceDetailsPlaceRequestElementOptions
。
撥打 const {PlaceDetailsPlaceRequestElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceDetailsPlaceRequestElement |
PlaceDetailsPlaceRequestElement([options]) 參數:
|
屬性 | |
---|---|
place |
類型:
Place optional 預設值:
null 要在 Place Details Compact 元素中顯示詳細資料的地點物件、ID 或資源名稱。這項屬性會以資源名稱的形式反映至屬性。
HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceDetailsPlaceRequestElementOptions interface
google.maps.places.PlaceDetailsPlaceRequestElementOptions
介面
「PlaceDetailsPlaceRequestElement
」的選項。
屬性 | |
---|---|
place optional |
類型:
Place|string optional |
PlaceDetailsLocationRequestElement class
google.maps.places.PlaceDetailsLocationRequestElement
class
設定 PlaceDetailsCompactElement
或 PlaceDetailsElement
,根據位置載入資料。將這個元素附加為 PlaceDetailsCompactElement
或 PlaceDetailsElement
的子項,即可載入指定位置的資料。例如:
<gmp-place-details>
<gmp-place-details-location-request
location="37.6207665,-122.4284806"
></gmp-place-details-location-request>
</gmp-place-details>
自訂元素:
<gmp-place-details-location-request location="lat,lng"></gmp-place-details-location-request>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceDetailsLocationRequestElementOptions
。
撥打 const {PlaceDetailsLocationRequestElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceDetailsLocationRequestElement |
PlaceDetailsLocationRequestElement([options]) 參數:
|
屬性 | |
---|---|
location |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional 預設值:
null 要在 Place Details 元素中顯示詳細資料的位置。正規化為
LatLngAltitude 。HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceDetailsLocationRequestElementOptions interface
google.maps.places.PlaceDetailsLocationRequestElementOptions
介面
「PlaceDetailsLocationRequestElement
」的選項。
屬性 | |
---|---|
location optional |
類型:
LatLng|LatLngLiteral|LatLngAltitude|LatLngAltitudeLiteral optional 要顯示地點的位置。 |
PlaceSearchElement class
google.maps.places.PlaceSearchElement
class
以清單形式顯示地點搜尋結果。附加 PlaceTextSearchRequestElement
或 PlaceNearbySearchRequestElement
,指定要算繪結果的要求。附加 PlaceContentConfigElement
、PlaceStandardContentElement
或 PlaceAllContentElement
,指定要算繪的內容。
示例:
<gmp-place-search>
<gmp-place-text-search-request
text-query="QUERY"
></gmp-place-text-search-request>
<gmp-place-content-config>
<gmp-place-media lightbox-preferred></gmp-place-media>
</gmp-place-content-config>
</gmp-place-search>
如要使用 Place Search Element,請在 Google Cloud 控制台中為專案啟用 Places UI Kit API。
自訂元素:
<gmp-place-search attribution-position="top" orientation="vertical" selectable truncation-preferred></gmp-place-search>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceSearchElementOptions
。
撥打 const {PlaceSearchElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceSearchElement |
PlaceSearchElement([options]) 參數:
|
屬性 | |
---|---|
attributionPosition |
類型:
PlaceSearchAttributionPosition optional 預設值:
PlaceSearchAttributionPosition.TOP 歸因標誌和法律揭露按鈕的位置。
HTML 屬性:
|
orientation |
類型:
PlaceSearchOrientation optional 預設值:
PlaceSearchOrientation.VERTICAL 元素的方向變體 (垂直或水平)。
HTML 屬性:
|
places |
僅供檢視。 Place 物件陣列,內含目前算繪地點的 ID、位置和檢視區塊。 |
selectable |
類型:
boolean optional 預設值:
false 清單項目是否可選取。如果為 true,清單項目會是按鈕,點按時會分派
gmp-select 事件。也支援無障礙鍵盤導覽和選取功能。HTML 屬性:
|
truncationPreferred |
類型:
boolean optional 預設值:
false 如果設為 true,系統會截斷特定內容行,以便在單行顯示所有內容,而不是換行。
HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
事件 | |
---|---|
gmp-error |
function(event) 引數:
當後端要求遭到拒絕時 (例如 API 金鑰不正確),就會觸發這項事件。這個事件不會冒泡。 |
gmp-load |
function(event) 引數:
當元素載入並算繪內容時,系統會觸發這個事件。這個事件不會冒泡。 |
gmp-select |
function(event) 引數:
從清單中選取地點時,系統會觸發這個事件。包含 Place 物件,內含所選地點的 ID、位置和檢視區塊。 |
PlaceSearchElementOptions interface
google.maps.places.PlaceSearchElementOptions
介面
「PlaceSearchElement
」的選項。
屬性 | |
---|---|
attributionPosition optional |
類型:
PlaceSearchAttributionPosition optional |
orientation optional |
類型:
PlaceSearchOrientation optional 詳情請參閱《 PlaceSearchElement.orientation 》。 |
selectable optional |
類型:
boolean optional |
truncationPreferred optional |
類型:
boolean optional |
PlaceSearchAttributionPosition 常數
google.maps.places.PlaceSearchAttributionPosition
常數
「PlaceSearchElement
」的歸因位置。
撥打 const {PlaceSearchAttributionPosition} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
常數 | |
---|---|
BOTTOM |
PlaceSearchElement 底部的歸因資訊 |
TOP |
PlaceSearchElement 頂端的出處資訊 |
PlaceSearchOrientation 常數
google.maps.places.PlaceSearchOrientation
常數
「PlaceSearchElement
」的螢幕方向變體。
撥打 const {PlaceSearchOrientation} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
常數 | |
---|---|
HORIZONTAL |
橫向。 |
VERTICAL |
直向。 |
PlaceSelectEvent class
google.maps.places.PlaceSelectEvent
class
從地點清單中選取地點時,系統會觸發這個事件。使用 event.place
存取選取範圍。
這個類別會擴充 Event
。
撥打 const {PlaceSelectEvent} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
屬性 | |
---|---|
place |
類型:
Place 所選地點。 |
PlaceNearbySearchRequestElement class
google.maps.places.PlaceNearbySearchRequestElement
class
設定 PlaceSearchElement
,根據附近的搜尋要求載入結果。搜尋元素必須有 locationRestriction
屬性才能載入。如未設定 locationRestriction
,系統會忽略其他已設定的屬性。將這個元素附加為 PlaceSearchElement
的子項,即可載入結果。例如:
<gmp-place-search>
<gmp-place-nearby-search-request
location-restriction="RADIUS@LAT,LNG"
></gmp-place-nearby-search-request>
<gmp-place-content-config>
<gmp-place-media lightbox-preferred></gmp-place-media>
</gmp-place-content-config>
</gmp-place-search>
自訂元素:
<gmp-place-nearby-search-request excluded-primary-types="excluded-primary-type1 excluded-primary-type2..." excluded-types="excluded-type1 excluded-type2..." included-primary-types="included-primary-type1 included-primary-type2..." included-types="included-type1 included-type2..." location-restriction="radius@lat,lng" max-result-count="number" rank-preference="preference"></gmp-place-nearby-search-request>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceNearbySearchRequestElementOptions
。
撥打 const {PlaceNearbySearchRequestElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceNearbySearchRequestElement |
PlaceNearbySearchRequestElement([options]) 參數:
|
屬性 | |
---|---|
excludedPrimaryTypes |
類型:
Array<string> optional 預設值:
null HTML 屬性:
|
excludedTypes |
類型:
Array<string> optional 預設值:
null HTML 屬性:
|
includedPrimaryTypes |
類型:
Array<string> optional 預設值:
null HTML 屬性:
|
includedTypes |
類型:
Array<string> optional 預設值:
null HTML 屬性:
|
locationRestriction |
類型:
Circle|CircleLiteral optional 預設值:
null HTML 屬性:
|
maxResultCount |
類型:
number optional 預設值:
null HTML 屬性:
|
rankPreference |
類型:
SearchNearbyRankPreference optional 預設值:
null HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceNearbySearchRequestElementOptions 介面
google.maps.places.PlaceNearbySearchRequestElementOptions
介面
「PlaceNearbySearchRequestElement
」的選項。
屬性 | |
---|---|
excludedPrimaryTypes optional |
類型:
Array<string> optional |
excludedTypes optional |
類型:
Array<string> optional |
includedPrimaryTypes optional |
類型:
Array<string> optional |
includedTypes optional |
類型:
Array<string> optional |
locationRestriction optional |
類型:
Circle|CircleLiteral optional |
maxResultCount optional |
類型:
number optional 要傳回的結果數上限。詳情請參閱 PlaceNearbySearchRequestElement.maxResultCount 和 SearchNearbyRequest.maxResultCount 。 |
rankPreference optional |
類型:
SearchNearbyRankPreference optional 回覆中結果的排序方式。詳情請參閱 PlaceNearbySearchRequestElement.rankPreference 和 SearchNearbyRankPreference 。 |
PlaceTextSearchRequestElement class
google.maps.places.PlaceTextSearchRequestElement
class
設定 PlaceSearchElement
,根據文字搜尋要求載入結果。搜尋元素必須有 textQuery
屬性才能載入。如未設定 textQuery
,系統會忽略其他已設定的屬性。將這個元素附加為 PlaceSearchElement
的子項,即可載入結果。例如:
<gmp-place-search>
<gmp-place-text-search-request
text-query="QUERY"
></gmp-place-text-search-request>
<gmp-place-content-config>
<gmp-place-media lightbox-preferred></gmp-place-media>
</gmp-place-content-config>
</gmp-place-search>
自訂元素:
<gmp-place-text-search-request ev-connector-types="ev-connector-type1 ev-connector-type2..." ev-minimum-charging-rate-kw="rate" included-type="type" is-open-now="true" location-bias="lat,lng" location-restriction="swlat,swlng|nelat,nelng" max-result-count="number" min-rating="number" price-levels="price-level1 price-level2..." rank-preference="preference" text-query="string" use-strict-type-filtering></gmp-place-text-search-request>
這個類別會擴充 HTMLElement
。
這個類別會實作 PlaceTextSearchRequestElementOptions
。
撥打 const {PlaceTextSearchRequestElement} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
PlaceTextSearchRequestElement |
PlaceTextSearchRequestElement([options]) 參數:
|
屬性 | |
---|---|
evConnectorTypes |
類型:
Array<EVConnectorType> optional 預設值:
null HTML 屬性:
|
evMinimumChargingRateKw |
類型:
number optional 預設值:
null HTML 屬性:
|
includedType |
類型:
string optional 預設值:
null HTML 屬性:
|
isOpenNow |
類型:
boolean optional 預設值:
null HTML 屬性:
|
locationBias |
類型:
string|LatLngAltitude|LatLngBounds|Circle|LatLng|LatLngLiteral|LatLngAltitudeLiteral|LatLngBoundsLiteral|CircleLiteral optional 預設值:
null HTML 屬性:
|
locationRestriction |
類型:
LatLngBounds|LatLngBoundsLiteral optional 預設值:
null HTML 屬性:
|
maxResultCount |
類型:
number optional 預設值:
null HTML 屬性:
|
minRating |
類型:
number optional 預設值:
null HTML 屬性:
|
priceLevels |
類型:
Array<PriceLevel> optional 預設值:
null HTML 屬性:
|
rankPreference |
類型:
SearchByTextRankPreference optional 預設值:
null HTML 屬性:
|
textQuery |
類型:
string optional 預設值:
null HTML 屬性:
|
useStrictTypeFiltering |
類型:
boolean optional 預設值:
null HTML 屬性:
|
方法 | |
---|---|
addEventListener |
addEventListener(type, listener[, options]) 參數:
傳回值:
void 設定函式,每當指定事件傳送至目標時,系統就會呼叫該函式。請參閱 addEventListener。 |
removeEventListener |
removeEventListener(type, listener[, options]) 參數:
傳回值:
void 從目標中移除先前透過 addEventListener 註冊的事件監聽器。請參閱「removeEventListener」。 |
PlaceTextSearchRequestElementOptions 介面
google.maps.places.PlaceTextSearchRequestElementOptions
介面
「PlaceTextSearchRequestElement
」的選項。
自動完成 類別
google.maps.places.Autocomplete
class
這個小工具會根據使用者輸入的文字提供地點預測結果。這個指令會附加至 text
類型的輸入元素,並監聽該欄位中的文字輸入內容。預測結果清單會以下拉式清單的形式顯示,並在輸入文字時更新。
這個類別會擴充 MVCObject
。
撥打 const {Autocomplete} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
Autocomplete |
Autocomplete(inputField[, opts]) 參數:
建立 Autocomplete 的新例項,並使用指定選項附加至指定輸入文字欄位。 |
方法 | |
---|---|
getBounds |
getBounds() 參數:無
傳回值:
LatLngBounds|undefined 偏差界限。傳回預測結果的偏誤範圍。 |
getFields |
getFields() 參數:無
傳回值:
Array<string>|undefined 成功擷取詳細資料時,傳回要在詳細資料回應中納入的 Place 欄位。如需欄位清單,請參閱 PlaceResult 。 |
getPlace |
getPlace() 參數:無
傳回值:
PlaceResult 使用者選取的地點。如果成功擷取詳細資料,系統會傳回使用者選取的地點詳細資料。否則會傳回 Place 物件的存根,並將 name 屬性設為輸入欄位的目前值。 |
setBounds |
setBounds(bounds) 參數:
傳回值:無
設定要傳回地點結果的偏好區域。結果可能會優先 (但不限於) 顯示這個區域的地點。 |
setComponentRestrictions |
setComponentRestrictions(restrictions) 參數:
傳回值:無
設定元件限制。元件限制用於將預測結果限制在父項元件內。例如國家/地區。 |
setFields |
setFields(fields) 參數:
傳回值:無
設定成功擷取詳細資料時,要在詳細資料回應中納入的地點欄位。如需欄位清單,請參閱 PlaceResult 。 |
setOptions |
setOptions(options) 參數:
傳回值:無
|
setTypes |
setTypes(types) 參數:
傳回值:無
設定要傳回的預測類型。如要瞭解支援的類型,請參閱 開發人員指南。如果未指定類型,系統會傳回所有類型。 |
已繼承:
addListener 、
bindTo 、
get 、
notify 、
set 、
setValues 、
unbind 、
unbindAll
|
事件 | |
---|---|
place_changed |
function() 引數:無
當使用者選取的地點提供 PlaceResult 時,系統會觸發這項事件。如果使用者輸入控制項未建議的地點名稱並按下 Enter 鍵,或地點詳細資料要求失敗,則 PlaceResult 會在 name 屬性中包含使用者輸入的內容,且未定義其他屬性。 |
AutocompleteOptions 介面
google.maps.places.AutocompleteOptions
介面
可在 Autocomplete
物件上設定的選項。
屬性 | |
---|---|
bounds optional |
類型:
LatLngBounds|LatLngBoundsLiteral optional 要搜尋地點的區域。 |
componentRestrictions optional |
類型:
ComponentRestrictions optional 元件限制。元件限制用於將預測結果限制在父項元件內。例如國家/地區。 |
fields optional |
類型:
Array<string> optional 成功擷取詳細資料時,詳細資料回應中要納入的 Place 欄位,這些欄位會產生費用。如果傳入 ['ALL'] ,系統會傳回所有可用的欄位並據此收費 (不適用於實際工作環境部署作業)。如需欄位清單,請參閱 PlaceResult 。您可以使用點路徑指定巢狀欄位 (例如 "geometry.location" )。預設值為 ['ALL'] 。 |
|
類型:
boolean optional 是否只擷取地點 ID。系統觸發 place_changed 事件時,可用的 PlaceResult 只會包含 place_id、types 和 name 欄位,以及 Autocomplete 服務傳回的 place_id、types 和 description。預設為停用。 |
strictBounds optional |
類型:
boolean optional 布林值,表示 Autocomplete 小工具只能傳回查詢當下位於小工具界線內的地點。將 strictBounds 設為 false (預設值) 時,結果可能會優先 (但不限於) 顯示邊界內的地點。 |
types optional |
類型:
Array<string> optional 要傳回的預測類型。如要瞭解支援的類型,請參閱 開發人員指南。如果未指定類型,系統會傳回所有類型。 |
SearchBox class
google.maps.places.SearchBox
class
這個小工具會根據使用者輸入的文字提供查詢預測。這個指令會附加至 text
類型的輸入元素,並監聽該欄位中的文字輸入內容。預測結果清單會以下拉式清單的形式顯示,並在輸入文字時更新。
這個類別會擴充 MVCObject
。
撥打 const {SearchBox} = await google.maps.importLibrary("places")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
SearchBox |
SearchBox(inputField[, opts]) 參數:
建立 SearchBox 的新例項,並使用指定選項附加至指定輸入文字欄位。 |
方法 | |
---|---|
getBounds |
getBounds() 參數:無
傳回值:
LatLngBounds|undefined 傳回查詢預測結果的偏誤範圍。 |
getPlaces |
getPlaces() 參數:無
傳回值:
Array<PlaceResult>|undefined 傳回使用者選取的查詢,用於 places_changed 事件。 |
setBounds |
setBounds(bounds) 參數:
傳回值:無
設定用於查詢預測偏誤的區域。結果只會優先顯示這個區域的地點,但不會完全限制於此。 |
已繼承:
addListener 、
bindTo 、
get 、
notify 、
set 、
setValues 、
unbind 、
unbindAll
|
事件 | |
---|---|
places_changed |
function() 引數:無
使用者選取查詢時會觸發此事件, getPlaces 則用於取得新地點。 |
SearchBoxOptions interface
google.maps.places.SearchBoxOptions
介面
可在 SearchBox
物件上設定的選項。
屬性 | |
---|---|
bounds optional |
類型:
LatLngBounds|LatLngBoundsLiteral optional 要將查詢預測結果偏向的區域。預測結果可能會優先 (但不限於) 顯示這些邊界內的地點。 |