我缺少什么使这项工作(地址只是任意的)。我没有得到任何firebug 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 :(得分:0)
发现它......吸收浪费时间:
<body onload="initialize()">