我试图在我的网站上放置谷歌地图,但它不起作用。这是我的代码。任何人都可以告诉我我做错了什么。感谢
<head>
<title>Environment Impact</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>
<script type="text/javascript">
function initialize() {
var california = new google.maps.LatLng(-122.23354, 37.48787);
var myOptions = {
center: california,
zoom: 8,
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="width:800px; height:600px; border:1px solid #000;"></div>
</body>
答案 0 :(得分:2)
您的脚本行应
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
同样california
不是有效的中心,你需要一个类似于:
center: new google.maps.LatLng(37.19533058280067, -120.234375),
答案 1 :(得分:2)
错误
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>
右
<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=true"></script>
答案 2 :(得分:2)
您的格式错误,可能还有错误的参数:
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>
应该是这样的:
<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=TRUE"></script>
确保将MY_API_KEY
替换为您的Google Map API密钥,或者只是在您不需要时忽略此参数。
不确定您希望sensor
发送到TRUE
,我猜对了,因为您有一个孤儿=TRUE
参数
答案 3 :(得分:1)
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>
这根本不对
<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=false"></script>
如果那是问题,会更接近
答案 4 :(得分:0)
是脚本标签需要
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
并设置sensor = false
答案 5 :(得分:0)