开发者

Google Maps: Can't get InfoWindow to display

I'm creating a map with a Marker and an InfoWindow. Everything seems to be working except the InfoWindow. I'm not seeing any errors in Firebug either.

Here's my 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);
开发者_StackOverflow社区            });
        } else {
            alert('Geocode was not successful for the following reason: ' + status);
        }
    });
}


Ugh, I found the answer. Silly typo by me.

This bit:

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

Should be:

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

I was setting an incorrect parameter for the config. title should have been content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜