Google map pops when I push markers

Asked

Viewed 123 times

1

My function to add markers to the map is as follows::

function setMarkers(map, locations) {
              var i
              for (i = 0; i < locations.length; i++)
              {  
                  var loan = locations[i][0]
                  var lat = locations[i][1]
                  var long = locations[i][2]
                  var add =  locations[i][3]
                  var image = locations[i][4]

                  latlngset = new google.maps.LatLng(lat, long);

                  var marker = new google.maps.Marker({  
                      position: latlngset,
                      title: loan, 
                      icon: image, 
                      map: map  
                  });
                  var content = "<strong>Nome: </strong>" + loan +  '</br>' + "<strong>Morada: </strong>" + add     
                  var infowindow = new google.maps.InfoWindow()

                  google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
                      return function() {
                          infowindow.setContent(content);
                          infowindow.open(map,marker);
                      };
                  })
                  (marker,content,infowindow)); 
              }
          }

Since I need to remove some Markers when a checbox is clicked, I have been researching and have the following code put:

var marker = new google.maps.Marker({  
                      position: latlngset,
                      title: loan, 
                      icon: image, 
                      map: map  
                  });

                 gmarkers.push(marker);

whereas gmarkers = [];

But in the gmarkers.push(marker); the map explodes. What I may be doing wrong?

  • 2

    Friend, what did you mean by "the map explodes"? What error does it make? Something appears on the console?

  • when I put an Alert before the line and after the line, the one before it triggers the Alert and the other no longer

  • look at the console. Do this, before gmarkers.push(Marker) gives you a console.log(Marker) and looks at the Chrome console to see what’s showing up. If you have any questions open your application in Chrome to press Ctrl+shift+i and see in the console tab

  • I did what you asked and with the push I got the following _.Xd line {_gm: Object, gm_accessors: Object, position: .L, gm_bindings: Object, title: "Av. of Freedom 245"... } without the push I got all the markers I have.

  • But no error appears on the console?

  • @Andrévicente, no error appears, I think it is because he "burst".

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.