Google maps 谷歌地图:在正确位置创建点后更新我的地图

Google maps 谷歌地图:在正确位置创建点后更新我的地图,google-maps,Google Maps,我试着在谷歌地图上画画,但我遇到了问题。当我编辑位置创建点谷歌地图复制我的点,我得到两个点:旧的和新的 let pointCord = []; function createRoute(e) { const lat = e.latLng.lat(); const lng = e.latLng.lng(); pointCord.push(new google.maps.LatLng(lat, lng)); const flightPathOptions = { path: poin

我试着在谷歌地图上画画,但我遇到了问题。当我编辑位置创建点谷歌地图复制我的点,我得到两个点:旧的和新的

let pointCord = [];    
function createRoute(e) {
const lat = e.latLng.lat();
const lng = e.latLng.lng();

pointCord.push(new google.maps.LatLng(lat, lng));

const flightPathOptions = {
  path: pointCord,
  editable: true,
  draggable: true,
  strokeColor: '#000',
  strokeOpacity: 1.0,
  strokeWeight: 5,
  map
};

flightPath = new google.maps.Polyline(flightPathOptions);
const getPath = flightPath.getPath();

map.addListener('click', createRoute);
我尝试应用这个代码

google.maps.event.addListener(getPath, 'set_at', function(){
   pointCord = getPath.getArray();
   createRoute(e);
});

但别帮我。如何删除旧点并更新我的地图

你的问题是flightPath内部createRoute。需要你的飞行路径离开你的功能

    const flightPathOptions = {
      path: pointCord,
      editable: true,
      draggable: true,
      strokeColor: '#000',
      strokeOpacity: 1.0,
      strokeWeight: 5,
      map
    };

    flightPath = new google.maps.Polyline(flightPathOptions);
    const getPath = flightPath.getPath();

    function createRoute(e) {
       getPath.push(e.latLng);
    }

    map.addListener('click', createRoute);