0

I'd like a javascript link that will remove the directions from my map.

Elsewhere on this forum Remove directions from google map api v3 someone asked a similar question and had a solution - but the solution doesn't work for me. Based on that I've tried:

 function clearDirections() {
directionDisplay = new google.maps.DirectionsRenderer();
directionDisplay.suppressMarkers = true;
directionDisplay.setMap(null);
return false;
 }

What am I doing wrong?

Community
  • 1
  • 1
webewitch
  • 89
  • 4
  • 10

1 Answers1

1

Hmm, that function creates a new renderer, and then displays it on no map. Ie it does nothing.

You need to keep a reference to the original directions display - so that you can the setMap(null) - which will remove it from the map.

barryhunter
  • 20,886
  • 3
  • 30
  • 43
  • Sorry but I can't figure out how to do that. My map is based on Google's example: http://code.google.com/apis/maps/documentation/javascript/examples/directions-complex.html – webewitch Mar 13 '12 at 16:52
  • If you provide a link to your map, maybe someone could help you. In that example, directionDisplay is already a global variable, although there is a typo, as it uses directionsDisplay later. – barryhunter Mar 13 '12 at 17:22
  • Brilliant! I had emulated the typo. I changed it to the conventional directionDisplay then this function did the trick: 'function clearDirections() { document.getElementById("directionsPanel").innerHTML =""; directionDisplay.setMap(null); return false; }' Thank you! – webewitch Mar 13 '12 at 18:25
  • oops . I was still left with custom markers. Final Code: ' function clearDirections() { if (markerArray) { for (var i = 0; i < markerArray.length; i++ ) { markerArray[i].setMap(null); } } document.getElementById("directionsPanel").innerHTML =""; directionDisplay.setMap(null); return false; }' – webewitch Mar 13 '12 at 18:44