Foros del Web » Programando para Internet » Javascript »

[SOLUCIONADO] borrar marcadores google maps

Estas en el tema de borrar marcadores google maps en el foro de Javascript en Foros del Web. Hola bueno queria saber si saben como se borran los marcadores.... En google maps... Por ejemplo yo tengo un xml de donde extraigo los datos... ...
  #1 (permalink)  
Antiguo 31/01/2013, 02:19
 
Fecha de Ingreso: junio-2010
Mensajes: 752
Antigüedad: 13 años, 10 meses
Puntos: 5
borrar marcadores google maps

Hola bueno queria saber si saben como se borran los marcadores.... En google maps...
Por ejemplo yo tengo un xml de donde extraigo los datos...
Bueno...al mapa se le van a agregando marcadores... Yo quiero eliminarlos. Si les parece facil quiero borrar todos..los marcadores

Lei algo de setmap .null .pero.no.se bien donde va...
  #2 (permalink)  
Antiguo 31/01/2013, 04:11
Avatar de ipraetoriux  
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años
Puntos: 155
Respuesta: borrar marcadores google maps

...seguramente cuando has agregado los marcadores has creado un array para pasar cada elemento del mismo al objeto google.map.Marker y asi ubicarlos en el mapa...

supongamos que el array se llama...arrayMarcadores;

...tienes que crear una funcion que recorra el array y elimine cada marcador y luego vaciar el array...

Código Javascript:
Ver original
  1. function LimpiarMarcadores() {
  2.     for (var i = 0; i < arrayMarcadores.length; i++) {
  3.         arrayMarcadores[i].setMap(null);
  4.     };
  5.  
  6.     arrayMarcadores= [];
  7.  
  8. }

Última edición por ipraetoriux; 31/01/2013 a las 04:21
  #3 (permalink)  
Antiguo 31/01/2013, 10:54
 
Fecha de Ingreso: junio-2010
Mensajes: 752
Antigüedad: 13 años, 10 meses
Puntos: 5
Respuesta: borrar marcadores google maps

Cita:
Iniciado por ipraetoriux Ver Mensaje
...seguramente cuando has agregado los marcadores has creado un array para pasar cada elemento del mismo al objeto google.map.Marker y asi ubicarlos en el mapa...

supongamos que el array se llama...arrayMarcadores;

...tienes que crear una funcion que recorra el array y elimine cada marcador y luego vaciar el array...

Código Javascript:
Ver original
  1. function LimpiarMarcadores() {
  2.     for (var i = 0; i < arrayMarcadores.length; i++) {
  3.         arrayMarcadores[i].setMap(null);
  4.     };
  5.  
  6.     arrayMarcadores= [];
  7.  
  8. }


yo leo de un XML externo, creo que en mi caso no tengo un array...

coloco los marcadores en un array ??? entonces y hago lo qe me dijiste,,

Código PHP:
        $(xml).find("marker").each(function(){
        
        
                
        
        
            var 
name = $(this).find('nombre_medico').text();
        
//    var address = $(this).find('address').text();
            
var address "holaaa";
            
            
            
// create a new LatLng point for the marker
            
var lat = $(this).find('latitud').text();
            var 
lng = $(this).find('longitud').text();
            var 
point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
            
            
// extend the bounds to include the new point
            
MYMAP.bounds.extend(point);
            
            var 
marker = new google.maps.Marker({
                
positionpoint,
                
mapMYMAP.map
            
});
            
            var 
infoWindow = new google.maps.InfoWindow();
            var 
html='<strong>'+name+'</strong.><br />'+address;
            
google.maps.event.addListener(marker'click', function() {
                
infoWindow.setContent(html);
                
infoWindow.open(MYMAP.mapmarker);
            });
            
MYMAP.map.fitBounds(MYMAP.bounds);
        }); 
  #4 (permalink)  
Antiguo 01/02/2013, 11:39
 
Fecha de Ingreso: junio-2010
Mensajes: 752
Antigüedad: 13 años, 10 meses
Puntos: 5
Respuesta: borrar marcadores google maps

por que no me anda este????


filename es el XML.... en el momoento de qe vuelvo a leer desde el XML, coloco setMAP... y no me los borra....


Código PHP:

MYMAP
.borrar = function(filename) {


    $.
get(filename, function(xml){
    
    
//  var markers = [];
    
        
$(xml).find("marker").each(function(){
        

            
            
// create a new LatLng point for the marker
            
var lat = $(this).find('latitud').text();
            var 
lng = $(this).find('longitud').text();
            var 
point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
            
            
// extend the bounds to include the new point
            
MYMAP.bounds.extend(point);
            
            var 
marker = new google.maps.Marker({
                
positionpoint
                    
//map: MYMAP.map    
            
});
            
            
        
marker.setMap(null);
    
            
            
            
            
MYMAP.map.fitBounds(MYMAP.bounds);
        });
    });
    
    
    
    

  #5 (permalink)  
Antiguo 01/02/2013, 13:45
Avatar de ipraetoriux  
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años
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.     }
  #6 (permalink)  
Antiguo 02/02/2013, 23:29
 
Fecha de Ingreso: junio-2010
Mensajes: 752
Antigüedad: 13 años, 10 meses
Puntos: 5
Respuesta: borrar marcadores google maps

ya lo habia resuelto...

la respuesta secreta era, que "var markers" ERA UNA VARIABLE GLOBAL..

ESTA DISPONIBLE, EL LA FUNCION AGREGAR MARCADORES. (MUESTRO LOS MARCADORES)

Y TAMBIEN ESTA DISPONIBLE EN BORRAR MARCADORES..
  #7 (permalink)  
Antiguo 02/02/2013, 23:33
Avatar de ipraetoriux  
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años
Puntos: 155
Respuesta: borrar marcadores google maps

... exactamente, si te fijas en el código que te envie yo la llamo var markerArray = []; y es global justamente para poder acceder a ella desde las otras funciones...

Etiquetas: google, maps, marcadores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:19.