In order to get custom info window, I am working with the InfoBox plug-in for google maps API V3 for the first time. I have the infoboxes with google places API content opening on click. But when I click a new marker the previous info box does not close. I only want one infobox open at a time. I attempted to follow the guidance in this questions: Google Map V3 - Allow only one infobox to be displayed at a time in my own code. Here is the relevant section of my code:
var boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, 0)
,zIndex: null
,boxStyle: {
background: "url('') no-repeat"
,opacity: 0.75
,width: "280px"
}
,closeBoxMargin: "10px 2px 2px 2px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
var ib = new InfoBox(myOptions);
var request = {
reference: place.reference
};
google.maps.event.addListener(marker,'click',function(e){
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
boxText.innerHTML = '<br><div><div style="font-size: 18px; vertical-align:top; border:2px solid; background-color:; color: #555555;"><b> '+place.name+'</b>';
if (!!place.website) contentStr += ' <a target="_blank" href="'+place.website+'"><img src="img/arrow.png" style="position:absolute; bottom:0px: right:0px; height:22px; width:22px;"></img></a></div></div>';
ib.close();
ib.open(map, marker);
} else {
var contentStr = "<h5>No Result, status="+status+"</h5>";
ib.close();
ib.open(map, marker);
}
});
});
gmarkers.push(marker);
Unfortunately I still have more than one infowindow at a time. Also is there another option to style the google API info window that does not require loading another script? This is going to run on a mobile website and if there is a way to only use CSS3 that would be preferable.
I solved the problem using this example http://www.geocodezip.com/fredagsmat_se_infoboxA.html which was picked up from this forum post https://groups.google.com/forum/?fromgroups=#!topic/google-maps-js-api-v3/gLHyTaKlJ2c.
If I understand correctly, you need to make your infobox variable global by placing it outside of the initialize function. In my case var ib = null;. Then you place ib = new InfoBox({}); right before the close of your initialize function. How you call the function will depend on your particular javascript but just refer to the example for some guidance.