地圖搜尋服務
透過 mapPlus PlacesService API 中的方法,可以搜尋地圖指定的地點。

開始使用
調用 new mapPlus.PlacesService(map, options)
,開始使用地圖搜尋API,以下為參數說明:
- map
(object)
: 帶入new mapPlus()
返回的物件。 - options
(object)
: 選填,可調整地圖搜尋的設定。
Name | Description |
---|---|
options.enableMultipleRequests boolean | 是否能允許同時發送多個請求,預設為 true 。 |
實例方法
PlacesService 提供五個地圖搜尋方法:
- findPlaceFromQuery: 可根據文字查詢傳回地點,例如地點的名稱或地址。
- findPlaceFromPhoneNumber: 可根據電話號碼傳回地點。
- textSearch: 可根據搜尋字串傳回附近地點的清單。
- getDetails: 可傳回特定地點的詳細資訊。
- nearBySearch: 可根據使用者的所在位置,傳回附近地點的清單。
findPlaceFromQuery
findPlaceFromQuery(request, callback)
可根據文字查詢傳回地點,例如地點的名稱或地址。
Parameters
- request
(object)
: 請求參數。 - callback
(function)
: 回調函數,返回第一個參數為查詢到的資料,第二個參數為請求狀態。
Name | Description |
---|---|
request.query (string) | 必填,要搜尋的文字字串,例如「便利商店」或「中正路 100 號」。 |
request.fields (string[]?) | 選填,要回傳的資料欄位。 |
request.locationBias (object?) | 選填,設定搜尋區域的範圍,詳細使用方法 locationBias。 |
Examples
findPlaceFromPhoneNumber
findPlaceFromPhoneNumber(request, callback)
可根據電話號碼傳回地點。
Parameters
- request
(object)
: 請求參數。 - callback
(function)
: 回調函數,返回第一個參數為查詢到的資料,第二個參數為請求狀態。
Name | Description |
---|---|
request.phoneNumber (string) | 必填,要搜尋的電話號碼。 |
request.fields (string[]?) | 選填,要回傳的資料欄位。 |
request.locationBias (object?) | 選填,設定搜尋區域的範圍,詳細使用方法 locationBias。 |
Examples
textSearch
textSearch(request, callback)
可根據搜尋字串傳回附近地點的清單。
Parameters
- request
(object)
: 請求參數。 - callback
(function)
: 回調函數,返回第一個參數為查詢到的資料,第二個參數為請求狀態。
Name | Description |
---|---|
request.text (string) | 必填,要搜尋的文字。 |
request.location (object?) | 選填,要搜尋的座標。 |
request.radius (number?) | 選填,以座標為中心的半徑範圍(單位:公尺)。 |
request.type (string?) | 選填,要搜尋的地點類型,詳細類型清單 Type List。 |
Examples
getDetails
getDetails(request, callback)
可傳回特定地點的詳細資訊。
Parameters
- request
(object)
: 請求參數。 - callback
(function)
: 回調函數,返回第一個參數為查詢到的資料,第二個參數為請求狀態。
Name | Description |
---|---|
request.placeId (string) | 必填,要搜尋的地點 ID。 |
request.fields (string[]?) | 選填,要回傳的資料欄位。 |
Examples
nearBySearch
nearBySearch(request, callback)
可根據使用者的所在位置,傳回附近地點的清單。
Parameters
- request
(object)
: 請求參數。 - callback
(function)
: 回調函數,返回第一個參數為查詢到的資料,第二個參數為請求狀態。
Name | Description |
---|---|
request.location (string?) | 選填,要搜尋的座標。 |
request.radius (number?) | 選填,以座標為中心的半徑範圍(單位:公尺)。 |
request.keyword (string?) | 選填,要搜尋的文字。 |
request.type (string?) | 選填,要搜尋的地點類型,詳細類型清單 Type List。 |
Examples
其他說明
locationBias
locationBias的參數可使用以下三種方式:
- 經緯度
- 以經緯度為中心的半徑範圍(單位:公尺)
- 矩形區域
經緯度
以經緯度為中心的半徑範圍(單位:公尺)
矩形區域