2010-11-01 55 views
1

我正在使用標記和InfoWindow創建地圖。除了InfoWindow,一切似乎都在工作。我在Firebug中也看不到任何錯誤。Google地圖:無法獲取InfoWindow以顯示

這裏是我的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); 
     } 
    }); 
} 

回答

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