我有要求,我需要创建可拖动的路线,并在某些点上我想要显示拖动路线上的点击坐标。DirectionsRenderer或任何其他替代方案上的Click事件
我实现这样的功能,
directionsDisplay.addListener('click', function(event) {
// Some opeation.
});
但点击事件上拖动的DirectionsRenderer不起作用。 我想对下图中显示的地图光标点击事件实施一些操作。
我有要求,我需要创建可拖动的路线,并在某些点上我想要显示拖动路线上的点击坐标。DirectionsRenderer或任何其他替代方案上的Click事件
我实现这样的功能,
directionsDisplay.addListener('click', function(event) {
// Some opeation.
});
但点击事件上拖动的DirectionsRenderer不起作用。 我想对下图中显示的地图光标点击事件实施一些操作。
从directions-draggable使用代码,你可以得到尽可能
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';
}
拖动路线时会返回坐标。如果我不拖动路线,我只需点击路线即可打印坐标。正如我在寻找这种情况的图片 –
中所示。等待 –
我想你必须从console.log(myroute.legs [i] .steps)中找到'作为该对象中存在的一个点 –
你想显示什么?做改变了方向路线的坐标。 –
@ Deep3015我想在这一点上得到协调。 –