Skip to main content

介紹

透過 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.LngLat

    new 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高速公路