我是谷歌地图api的新手,我正在尝试创建我的第一张地图,通过复制谷歌给你的例子,但不知何故,它不起作用。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=<MYKEY>&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
我正在使用博客来测试它,但是当我发布地图时却没有出现。我可以发布文字,但不能发布地图。想法?
答案 0 :(得分:1)
首先谷歌地图api不理解css 100%的任何div。
javascript
$( document ).ready(function() {
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
} initialize();
});
和HTML
<div id="map_canvas" style="width:300px; height:300px"></div>
的jsfiddle googleMap
答案 1 :(得分:0)
更改
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=<MYKEY>&sensor=true">
</script>
到
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=true">
</script>
或只是提供关键参数,如果你有