Google maps 实时创建和删除flightPath

Google maps 实时创建和删除flightPath,google-maps,Google Maps,我创建了flightPath,但无法使用它。我写了函数控制台'123',但不。。。如何使用flightPath const映射选项={ //映射选项 }; const map=new google.maps.map(document.getElementById('map'),mapOptions); 让flightPath={}; 函数createPoint(e){ //createPoint } 函数createLineBetweenPoints(){ 常量飞行选项={ //选择权 地图:地

我创建了flightPath,但无法使用它。我写了函数控制台'123',但不。。。如何使用flightPath

const映射选项={
//映射选项
};
const map=new google.maps.map(document.getElementById('map'),mapOptions);
让flightPath={};
函数createPoint(e){
//createPoint
}
函数createLineBetweenPoints(){
常量飞行选项={
//选择权
地图:地图
};
flightPath=新的google.maps.Polyline(flightPathOptions);
}
函数createRoutes(e){
创建点(e);
创建点之间的线(e);
}
map.addListener('click',createRoutes);
google.maps.event.addListener(flightPath,'click',function(){
console.log(123);//不工作
});

您试图将google maps事件侦听器添加到空对象
{}
,但该操作无效。一旦它存在,您需要将其添加到
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);
  });
}

已发布的
createPoint
函数没有任何作用(因此,已发布的代码无法创建多段线。请提供一个示例来说明您的问题。