2017-05-29 61 views
1

我有要求,我需要创建可拖动的路线,并在某些点上我想要显示拖动路线上的点击坐标。DirectionsRenderer或任何其他替代方案上的Click事件

我实现这样的功能,

directionsDisplay.addListener('click', function(event) { 
      // Some opeation. 
}); 

但点击事件上拖动的DirectionsRenderer不起作用。 我想对下图中显示的地图光标点击事件实施一些操作。

enter image description here

+0

你想显示什么?做改变了方向路线的坐标。 –

+0

@ Deep3015我想在这一点上得到协调。 –

回答

0

directions-draggable使用代码,你可以得到尽可能

Fiddle Demo

function computeTotalDistance(result) { 
    var total = 0; 
    var myroute = result.routes[0]; 
    for (var i = 0; i < myroute.legs.length; i++) { 
    //console.log(myroute.legs[i]) 
    console.log('Start Loc: ' + myroute.legs[i].start_location + 'Start Location: ' + myroute.legs[i].start_address); 
    console.log('End Loc:' + myroute.legs[i].end_location + 'End Location: ' + myroute.legs[i].end_address); 
    total += myroute.legs[i].distance.value; 
    } 
    total = total/1000; 
    document.getElementById('total').innerHTML = total + ' km'; 
} 
+0

拖动路线时会返回坐标。如果我不拖动路线,我只需点击路线即可打印坐标。正如我在寻找这种情况的图片 –

+0

中所示。等待 –

+0

我想你必须从console.log(myroute.legs [i] .steps)中找到'作为该对象中存在的一个点 –

相关问题