Reopen infowindow after closing it in google map

I have a map with a panorama of the street, an info industry and a draggable marker. After the marker is dragged, the function requests getPanoramaByLocation to find out if the viewing service is available. If it is not, it closes the info industry. This is great, but when I click the marker again, the infowindow no longer opens. Do you know what is wrong, please? TX

    var sv = new google.maps.StreetViewService();

    function initialize() {

        var optionMap = {
            zoom: 13,
            center: new google.maps.LatLng(47.390251,0.68882),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var myMap = new google.maps.Map(document.getElementById("mapDiv"), optionMap);
        var optionsMarker = {
            position: new google.maps.LatLng(47.390251,0.68882),
            map: myMap,
            draggable: true,
            title: "my marker"
            }
        var marker = new google.maps.Marker(optionsMarker);
        var infowindowDiv = '<div id="streetview" style="width:300px;height:200px;"' +'</div>';

        var infoWindow = new google.maps.InfoWindow({
            content: infowindowDiv,
            position: myMap.getCenter() });

        google.maps.event.addListener(marker, 'click', function() {
         infoWindow.open(myMap, marker);
         });

        google.maps.event.addListener(infoWindow, 'domready', function() {
            var panorama = new
        google.maps.StreetViewPanorama(document.getElementById("streetview"));
            panorama.setPosition(infoWindow.getPosition());

        google.maps.event.addListener(marker, 'dragend', function(event) {
          sv.getPanoramaByLocation(event.latLng, 50, processSVData);});             

        function processSVData(data, status) {
          if (status == google.maps.StreetViewStatus.OK) {

              var markerPanoID = data.location.pano;
              // Set the Pano to use the passed panoID
              panorama.setPano(markerPanoID);
              panorama.setPov({
                heading: 270,
                pitch: 0,
                zoom: 1
              });
              panorama.setVisible(true);
            } 
            else {
            infoWindow.close();
            infoWindow = null;              
            };
        }                   
    }); 
    }
+3
source share
2 answers

In the GMaps API docs:

close() None    Closes this InfoWindow by removing it from the DOM structure.

https://developers.google.com/maps/documentation/javascript/reference#InfoWindow

... , . . , , , "infoWindow = null;" . , , . , infowindow null, , .

+2

, html infobox DOM, , JS .

-, open,

myInfoWindow.open(mymap);

, "closeclick" infowindow

var infoWindowClosed = false;
google.maps.event.addListener(myInfoBox, "closeclick", function () {
    infoWindowClosed = true;
});

myInfoWindow

if(infoWindowClosed){
    myInfoWindow.open(mymap);
}
+1

All Articles