开发者

Google Maps: Can't get InfoWindow to display

开发者 https://www.devze.com 2023-01-23 13:44 出处:网络
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.

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

精彩评论

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