I am trying to use the Google Map API (V3) to drop pins on a map. I am able to place the pin and open an info box. Unfortunately the info box won't display HTML content, only a string. I am using the following code to create/display my pin/info box.
addMarker('1600 Pennsylvania Avenue, Washington DC');
function addMarker(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
boxText.innerHTML = "Hello World!";
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, 0)
,zIndex: null
,boxStyle: {
backgroundColor: '#ffffff'
,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);
google.maps.event.addListener(marker, 'click', function(){
if( ib.anchor === this ){
ib.close();
}
else {
ib.open(map, this);
}
});
}
});
}
When doing this, the infobox contents are always [object HTMLDivElement]
and I can not figure out how to have it properly display the informationfound in boxText
. The code for the info box is taken almost 100% straight from Google's own example.
So, the answer is incredibly simple. Use the most up-to-date version of infobox.js and it works fine.