我正尝试使用Google Map API(V3)放置地图上的图钉。我能够放置该针并打开一个信息框。不幸的是,信息框不会显示HTML内容,只有一个字符串。我正在使用下面的代码来创建/显示我的引脚/信息框。InfoBox不会加载HTML内容
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);
}
});
}
});
}
在这样做时,信息框内容始终[object HTMLDivElement]
,我无法弄清楚如何让它在boxText
正确显示informationfound。信息框的代码几乎100%直接从谷歌自己的例子。
你的代码适用于我:http://jsfiddle.net/doktormolle/Aqvba/ –
...对我也是 – davidkonrad
那么,这使得诊断更加困难。 – Jeremy1026