Tim*_*ers 4 javascript google-maps google-maps-api-3
我在使用Google Maps API时无法显示地图.我正在尝试构建一个应用程序,它不会在那里工作,但它在我已经制作的测试页面中也被破坏了.有谁知道我做错了什么?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
console.log("Initializing...");
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="height: 100%; width: 100%;"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.我很困惑!
Dan*_*llo 19
给你的map_canvasdiv一个固定的宽度和高度,你的例子将正常工作:
<div id="map_canvas" style="width: 500px; height: 400px;"></div>
Run Code Online (Sandbox Code Playgroud)
否则,请将高度设置为您html和bodyGoogle在API教程中的高度:
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13845 次 |
| 最近记录: |