我创建了flightPath,但我不能使用它。我写功能控制台'123',但不是吗......我怎么能使用flightPath?
const mapOptions = {
//mapOption
};
const map = new google.maps.Map(document.getElementById('map'), mapOptions);
let flightPath = {};
function createPoint(e) {
//createPoint
}
function createLineBetweenPoints() {
const flightPathOptions = {
//option
map: map
};
flightPath = new google.maps.Polyline(flightPathOptions);
}
function createRoutes(e) {
createPoint(e);
createLineBetweenPoints(e);
}
map.addListener('click', createRoutes);
google.maps.event.addListener(flightPath, 'click', function() {
console.log(123);// don't work
});
答案 0 :(得分:0)
您正在尝试将Google地图事件监听器添加到空对象{}
,但这不起作用。一旦存在,您需要将其添加到google.maps.Polyline
。
function createLineBetweenPoints() {
const flightPathOptions = {
//option
map: map,
};
flightPath = new google.maps.Polyline(flightPathOptions);
google.maps.event.addListener(flightPath, 'click', function() {
console.log(123);
});
}