介紹
透過 mapPlus DirectionsService API 中的方法,可以在地圖上規劃路線。
開始使用
調用 new mapPlus.DirectionsService(map),開始使用路線規劃 API,以下為參數說明:
- map
(object):帶入new mapPlus()返回的物件。
const map = await new mapPlus(document.getElementById('map'), {
accessToken: 'get_your_token',
accessKey: 'get_your_key',
style: 'https://kw3dmap.localking.com.tw/openapi/map/kwmap.etxt',
});
const service = new mapPlus.DirectionsService(map);
參數說明
Location
地標參數,可使用以下格式:
-
mapPlus.LngLatnew mapPlus.LngLat(121.52512916930945, 25.027326932236182) -
{lng, lat}{lng: 121.52512916930945, lat: 25.027326932236182} -
座標陣列
[121.52512916930945, 25.027326932236182] -
地名
warning注意:此為實驗性功能。建議先使用 PlacesService 取得欲查詢地名之座標。
{
text: '勤崴國際',
type: 'PLACE',
} -
地址
warning注意:此為實驗性功能。建議先使用 PlacesService 取得欲查詢地址之座標。
{
text: '台北市中正區羅斯福路二段100號',
type: 'ADDRESS',
}
TravelMode
交通方式。
| 交通方式 | 描述 |
|---|---|
| DRIVING | 汽車 |
| TWO_WHEELER | 機車 |
| BICYCLING | 腳踏車 |
| WALKING | 走路 |
| TRANSIT | 大眾運輸。 ※注意: 當設為 mode: 'TRANSIT' 時,將不支援航點 waypoints 設定。 |
Avoid
要避開的路線。
| 路線 | 描述 |
|---|---|
| TOLL | 收費路段 |
| HIGHWAY | 高速公路 |