谷歌地图:无法显示InfoWindow

时间:2010-11-01 16:58:57

标签: javascript google-maps google-maps-api-3

我正在创建一个带有Marker和InfoWindow的地图。除了InfoWindow之外,一切似乎都在起作用。我在Firebug中也没有看到任何错误。

这是我的JavaScript:

var myOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map;
var geocoder;
var marker;
var infowindow;

function initialize() {
    geocoder = new google.maps.Geocoder();
    geocoder.geocode({'address': '327 5th St, West Palm Beach, FL 33401-3995'}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            myOptions.center = results[0].geometry.location;
            map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
            marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location,
                title: 'Middle East Bakery & Grocery'
            });
            infowindow = new google.maps.InfoWindow({
                title: '<strong>Middle East Bakery &amp; Grocery</strong><br />327 5th St<br />West Palm Beach, FL 33401-3995'
            });
            infowindow.open(map, marker);
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map, marker);
            });
        } else {
            alert('Geocode was not successful for the following reason: ' + status);
        }
    });
}

1 个答案:

答案 0 :(得分:0)

呃,我找到了答案。我傻了。

这一位:

infowindow = new google.maps.InfoWindow({
    title: '<strong>Middle East Bakery &amp; Grocery</strong><br />327 5th St<br />West Palm Beach, FL 33401-3995'
});

应该是:

infowindow = new google.maps.InfoWindow({
    content: '<strong>Middle East Bakery &amp; Grocery</strong><br />327 5th St<br />West Palm Beach, FL 33401-3995'
});

我为配置设置了错误的参数。 title应该是content