我有一个简单的 HTML 页面,我想使用 API Access 显示谷歌地图。我使用这段代码:
<!DOCTYPE html><!-- HTML5 -->
<html lang="it" dir="ltr">
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=blablabla&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {center: new google.maps.LatLng(-34.397, 150.644), zoom: 8};
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
我确定脚本 block 已处理,但页面未显示 map 。
你能帮帮我吗?
最佳答案
//在头部放置这些样式
<head>
<style>
html{
height:100%;
}
body{
margin: 0;
padding: 0;
height:100%;
}
</style>
</head>
//在文档正文中,定义 map_canvas 的样式:
<body>
<div id="map_canvas" style="height:100%;"></div>
</body>
//右键单击您的文档并选择 insepct 元素。在开发人员//工具中选择控制台选项卡。如果那里没有显示错误,那么这可能会解决您的问题 //祝你好运 8-)
关于HTML 页面不显示谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20783213/