Google Maps API教程(https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map)给了我一个空白屏幕。我已经在这3个小时的工作,无法弄明白。
我甚至完全复制/粘贴了代码,它被保存为.html文件。
<!DOCTYPE html>
<html>
<head>
<style>
#map_canvas{
height: 500px;
width: 400px;
}
</style>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, ‘load’, initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
答案 0 :(得分:1)
您的代码中包含非法字符:
Timestamp: 08/12/2013 02:08:39 PM
Error: illegal character
Line: 21, Column: 48
Source Code:
google.maps.event.addDomListener(window, $(B!F(Bload$(B!G(B, initialize);
变化:
google.maps.event.addDomListener(window, ‘load’, initialize);
要:
google.maps.event.addDomListener(window, "load", initialize);
答案 1 :(得分:0)
您需要将&callback=initialize
添加到您的网址,该额外参数会告知Google这是要调用的功能。该功能必须可从window
范围访问。