我試圖創建從用戶當前位置到他選擇的目標的路線。問題是,我不知道如何讓用戶緯度/經度爲我的路由功能,看起來像這樣:使用MapQuest創建從用戶地理位置的路線Directions API
getRoute = function(){
dir = MQ.routing.directions()
.on('success', function(data) {
//does some stuff with the routes data/directions. not important here
});
dir.route({
locations: [
{ latLng: { lat: USER LAT HERE, lng: USER LNG HERE } },
{ latLng: { lat: (poiCoordinates.lat), lng: (poiCoordinates.lng) } }
],
options: {
//not important as well
}
});
mqroute = MQ.routing.routeLayer({
directions: dir,
}).addTo(map);
};
功能上面,當用戶選擇的興趣點,例如一個名爲餐館,然後點擊「查找路線」按鈕。我可以訪問Leaflet locate函數,但不知道如何合併它們並將用戶地理位置獲取到上面的getRoute函數中。任何建議的方式來做到這一點?乾杯!