Remove all Infowindow in google maps

Asked

Viewed 189 times

0

How do I remove all info.window in google maps.

Most examples give the following way:

var infowindow = null;

incia

se clicar

if(infowindow){
        infowindow.close();
}

My code is like this:

<script>
var infowindow = null;

//Rest of the google maps code...

  map.data.addListener('click', function(event) {

    if(infowindow){
        infowindow.close();
    }
    var infoWindow = new google.maps.InfoWindow();
    var iwContent = 'FOI';

    infoWindow.setContent(iwContent);
    var lat = event.latLng.lat();
    var lng = event.latLng.lng();
    infoWindow.setPosition(new google.maps.LatLng(lat,lng));     
    infoWindow.open(map);

  });

How do I correct? because it only returns to variable NULL ...

1 answer

-1

To work I have to do the following:

 map.data.addListener('click', function(event) {

    if(infoWindow){
        infoWindow.close();
    }

    var iwContent = 'FOI';
    infoWindow.setContent(iwContent);
    var lat = event.latLng.lat();
    var lng = event.latLng.lng();
    infoWindow.setPosition(new google.maps.LatLng(lat,lng));     
    infoWindow.open(map);   
  });


  var infoWindow = new google.maps.InfoWindow();

ATT

Browser other questions tagged

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