【问题标题】:Google Maps API v3 Street View "google is not defined"谷歌地图 API v3 街景“谷歌未定义”
【发布时间】: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


【解决方案1】:

路径中缺少协议。

//maps.googleapis.com/maps/api/js?sensor=false

应该是

http://maps.googleapis.com/maps/api/js?sensor=false

(很多例子都没有)

【讨论】:

猜你喜欢
  • 2015-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多