【发布时间】:2012-03-08 11:25:48
【问题描述】:
我刚刚开始使用 Maps API,我试图复制以下示例。
https://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html
当我复制源代码时,脚本中出现以下错误。
google 未定义 11号线 var fenway = new google.maps.LatLng(42.345573,-71.098326);
这是我正在使用的 html 文件。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example: Street View Layer</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script src="//maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var fenway = new google.maps.LatLng(42.345573,-71.098326);
var mapOptions = {
center: fenway,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(
document.getElementById("map_canvas"), mapOptions);
var panoramaOptions = {
position: fenway,
pov: {
heading: 34,
pitch: 10,
zoom: 1
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"),panoramaOptions);
map.setStreetView(panorama);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 400px; height: 300px"></div>
<div id="pano" style="position:absolute; left:410px; top: 8px; width: 400px; height: 300px;"></div>
</body>
</html>
谷歌示例加载完美,但我的代码没有。
我看到一些人收到此错误,但列出的修复似乎都不适用于我。我在复制脚本时是否犯了一个基本错误?
【问题讨论】:
-
您复制的代码运行良好。请确保它不是导致此错误的浏览器缓存中文件的旧版本。错误
google is not defined最常见的原因是您的 googlemap javascript 在使用其功能时未正确加载。
标签: javascript google-maps-api-3