2011-10-11 191 views
0

我错过了什么使这项工作(地址是任意的)。我没有得到萤火虫JS错误,但它只是没有显示地图。我在另一个页面上使用这个代码(并且它正在工作),所以肯定有某个地方我错过了。谢谢!谷歌地图JS不显示地图

<!DOCTYPE HTML> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Untitled Document</title> 
<style type="text/css"> 
#map_canvas { 
    height: 325px; 
    width: 325px; 
    border: 1px solid #999; 
} 
</style> 
</head> 

<body> 


<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
    var geocoder; 
    var map; 
    var address ="9712 West Northern Avenue Peoria,AZ 85345"; 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(-37.0625, 95.677068); 
    var myOptions = { 
     zoom: 11, 
     center: latlng, 
    mapTypeControl: true, 
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, 
    navigationControl: true, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     mapTypeControl: false, 
     panControl: false, 
     streetViewControl: false 
    }; 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    if (geocoder) { 
     geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { 
      map.setCenter(results[0].geometry.location); 

      var infowindow = new google.maps.InfoWindow(
       { content: '<b>'+address+'</b>', 
        size: new google.maps.Size(150,50) 
       }); 

      var marker = new google.maps.Marker({ 
       position: results[0].geometry.location, 
       map: map, 
       title:address 
      }); 
      google.maps.event.addListener(marker, 'click', function() { 
       infowindow.open(map,marker); 
      }); 

      } 
     } 
     }); 
    } 
    } 
</script> 
<div id="map_canvas"></div> 

</body> 
</html> 

回答

0

找到it..sorry的浪费时间:

<body onload="initialize()">