2017-12-18 100 views
-1

我尝试绘制谷歌地图,我有问题。当我编辑位置创建点谷歌地图重复我的观点,我得到两点:新旧。谷歌地图:正确的位置创建点后更新我的地图

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); 
}); 

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

回答

0

你的问题是flightPath内建createRoute。需要您的flightPath功能。

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);