Big Al
Big Al

Reputation: 13

How do I remove directions from a Google Map API v3 map?

I am new to API's and I have this to create my map but I want to take the driving directions out what should I change to get this to happen. I have a ton of markers being rendered from MySQL so I don't need to start over, just remove the directions.

Here is the web page.

This is the code for rendering the map:

var directionsService = new google.maps.DirectionsService(); 
var directionsDisplay = new google.maps.DirectionsRenderer(); 

var myOptions = { 
  zoom:7, 
  mapTypeId: google.maps.MapTypeId.ROADMAP 
} 

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map); 

var request = { 
    origin: '<?php echo $orgcitname; ?>',  
    destination: '<?php echo $descitname; ?>', 
    travelMode: google.maps.DirectionsTravelMode.DRIVING 
}; 

directionsService.route(request, function(response, status) { 
   if (status == google.maps.DirectionsStatus.OK) { 
      directionsDisplay.setDirections(response); 
   } 
});

Upvotes: 1

Views: 5000

Answers (2)

xcer
xcer

Reputation: 1707

To remove the directions from the map, you call the google.maps.DirectionsRenderer's setMap() function without any parameters. So in your case:

directionsDisplay.setMap();

Upvotes: 3

Duncan_m
Duncan_m

Reputation: 2546

   var myOptions = { 
     zoom:7, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
   } 

   var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

That will leave you with just your map.. no directions..

Upvotes: 0

Related Questions