我的代码如下:
var map = /*some google map - defined earlier in the code*/;
var geocoder = new google.maps.Geocoder();
var address = 'Some Address, Some Street, Some Place';
geocoder.geocode({'address':address},function(results,status){
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var infobox = new google.maps.InfoWindow({
content: 'Hello world'
});
for(i in results){
var marker = new google.maps.Marker({
map: map,
position: results[i].geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infobox.setContent('blablabla');
infobox.open(map,marker);
alert(infobox.content); //displays 'blablabla'
});
}
}
});
基本上它是基于给定的地址字符串在单个地图上创建一些标记。它会向单击时打开的标记添加一个infoWindow。
问题是:infoWindow显示为空。
屏幕截图:
PS:使用Maps API V3
答案 0 :(得分:23)
我遇到了同样的问题,并找到了非常简单的原因:信息窗口中的文本实际上是显示的,但是是白色的,因此在白色背景上看不到。通过CSS为内容提供不同的颜色解决了我的问题。
答案 1 :(得分:2)
基本上,您需要使用标记添加循环外部的功能将信息框消息添加到每个标记...有关示例和详细说明,请参阅: http://code.google.com/apis/maps/documentation/javascript/events.html#EventClosures
答案 2 :(得分:0)
我是这样做的。
var map,markersArray,infowindow; //infowindow has been declared as a global variable.
function initialize(){
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(51.5001524,-0.1262362),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
markersArray = [];
}
function createMarker(latlng, html,zoom) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
marker.MyZoom = zoom;
return marker;
}
答案 3 :(得分:0)
我已通过添加以下代码解决了问题。
setTimeout(function(){GeocodeMarker.info.open(GoogleMap, GeocodeMarker); },300);
由于