4
Google지도에 그려진 방향 경로를 삭제해야하나요? 마커를 제거하는 방법을 알고 있지만 마커를 제거하면 경로가 지워지지 않습니다. 다시 처음부터지도를 만드는 것보다 방향 경로를 제거 할 수있는 방법이 있습니까?google지도 방향 경로를 제거하는 방법?
Google지도에 그려진 방향 경로를 삭제해야하나요? 마커를 제거하는 방법을 알고 있지만 마커를 제거하면 경로가 지워지지 않습니다. 다시 처음부터지도를 만드는 것보다 방향 경로를 제거 할 수있는 방법이 있습니까?google지도 방향 경로를 제거하는 방법?
예, 마커를 제거하는 것과 같습니다 (Google에서 setMap을 표준으로 사용함). 좋은 방법은 항상 마커, 폴리 라인 및 directions..etc에 대한 전역 배열 변수를 정의한다 : 당신이 볼 수있는
var markers = [];
var drArr = [];
var pArr = [];
...
// whenever you set a marker, add it to the markers array
markers.push(marker);
...
// whenever you create a DirectionsRenderer instance, add it to the DirectionsRenderer array
drArr.push(directionsRenderer);
...
// whenever you create a Polyline instance, add it to the Polyline array
pArr.push(polypath);
// This is used to reset the map
function resetMap() {
// remove Markers
for(i=0; i < markers.length; i++)
markers[i].setMap(null);
// remove DirectionsRenderers
for(i=0; i < drArr.length; i++)
drArr[i].setMap(null);
// remove Polylines
for(i=0; i < pArr.length; i++)
pArr[i].setMap(null);
}
, 당신은 (resetMarkers..etc 같은) 기능에 resetMap 기능을 분리해서 할 수 있습니다.
희망 도움말.