Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/02/2013, 13:45
Avatar de ipraetoriux
ipraetoriux
 
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años, 9 meses
Puntos: 155
Respuesta: borrar marcadores google maps

Es que mi amiga estas agregando marcas y borrando a la misma vez...esto te debería quedar así, avísame si te funciona, sino copia todo el código de como estas trabajando con Google Maps y vemos....

1ero. Cuando creas las marcas, definí una variable global que haga referencia a un objeto array. No se como estarás llamando a la función para cargar el mapa, recorrer el xml y agregar las marcas, pero supongamos cargas el mapa y que lo haces con un window.onload

Código Javascript:
Ver original
  1. window.onload = function(){
  2.    cargarMapa();
  3. };
  4.  
  5. var markerArray = [];
  6. var map;
  7. var bounds;
  8.  
  9. function cargarMapa(){
  10.    
  11.    var mapOptions = {
  12.      center: new google.maps.LatLng(0,0),
  13.      zoom:2,
  14.      mapTypeId: google.maps.MapTypeId.ROADMAP
  15.    };
  16.  
  17.    bounds = new google.maps.LatLngBounds();
  18.    map = new google.maps.Map(document.getElementById('cargarMapa'), mapOptions);
  19.    agregarMarcas();
  20. }

Ahora agregas las marcas...y cada vez que creas una marca, almacenas la misma en un array, esto es para que cuando tengas que borrarlas, no tengas que recorrer todo el xml de nuevo, directamente recorres el array y borras

Código Javascript:
Ver original
  1. function agregarMarcas(){
  2.  
  3. $(xml).find("marker").each(function(){
  4.          
  5.             var name = $(this).find('nombre_medico').text();
  6.             //var address = $(this).find('address').text();
  7.             var address = "holaaa";
  8.              
  9.              
  10.             // create a new LatLng point for the marker
  11.             var lat = $(this).find('latitud').text();
  12.             var lng = $(this).find('longitud').text();
  13.             var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
  14.              
  15.  
  16.             bounds.extend(point);
  17.              
  18.             var marker = new google.maps.Marker({
  19.                 position: point,
  20.                 map: map
  21.             });
  22.            
  23.             markerArray.push(marker );
  24.  
  25.             var infoWindow = new google.maps.InfoWindow();
  26.             var html='<strong>'+name+'</strong.><br />'+address;
  27.             google.maps.event.addListener(marker, 'click', function() {
  28.                 infoWindow.setContent(html);
  29.                 infoWindow.open(map, marker);
  30.             });
  31.             map.fitBounds(bounds);
  32.         });  
  33. }

ahora cuando quieras borrar las marcas, llamas a la funcion borrarMarcas...

Código Javascript:
Ver original
  1. function borrarMarcas(){
  2.        for (var i = 0; i < markerArray.length; i++) {
  3.         markerArray[i].setMap(null);
  4.     };
  5.  
  6.     markerArray= [];
  7.     bounds = null;
  8.     bounds = new google.maps.LatLngBounds();
  9.     }