0

Please see following screenshot.

screenshot

My code is

function get(position, html, resultsMap){ 

    //alert(position);
     var getDirection = new google.maps.InfoWindow({
        content: '',
        position: position
    });
    getDirection.close();
     getDirection.setContent(html);  
       getDirection.open(resultsMap);  
    }  

Function call is

get(position, html, resultsMap); 

All this working fine except above issue. I want to close previous infoWindow and display only new Infowindow, when click another link ( all links has same class).How to fix.

JAL
  • 41,701
  • 23
  • 172
  • 300
Ming han
  • 17
  • 4
  • Only thing they can do is reduce my reputation :) – Ming han Feb 11 '16 at 22:08
  • 1
    I didnt downvote, but I think you deserve it. Please see some more well-asked questions and try to understand the difference. – Peyman Mohamadpour Feb 11 '16 at 23:48
  • possible duplicate of [Auto close InfoWindow in googlemap](http://stackoverflow.com/questions/28138468/auto-close-infowindow-in-googlemap) – geocodezip Feb 12 '16 at 00:33
  • possible duplicate of [close InfoWindow before open another](http://stackoverflow.com/questions/14321808/close-infowindow-before-open-another) – geocodezip Feb 12 '16 at 00:34

1 Answers1

0

Why not just reuse the infoWindow you already have for the new location?

HandleInfoWindow(self.places()[p], contentString, p);
map.setCenter(marker.location);


var HandleInfoWindow = function(place, content, index) {
      var position = {
        'lat': place.lat(),
        'lng': place.lng()
      };
      infoWindow.setContent(content);
      infoWindow.setPosition(position);
      infoWindow.open(map);
};
// Closes infoWindow
infoWindow.close();

Yes there is alot more code needed to get this all to work, but these parts will center your infoWindow and allow the reuse of it rather than creating who knows how many.

I've included also close code for you.

James Fehr
  • 106
  • 4