2012-03-08 156 views
1

我剛剛開始使用Maps API,並試圖複製以下示例。Google Maps API v3街景「google未定義」

https://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html

當我複製我得到以下錯誤的腳本的來源。

谷歌未定義 第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> 

在谷歌例加載完美,但我的代碼沒有。

我看到一些人得到這個錯誤,但沒有列出的修復程序似乎爲我工作。我是否在複製腳本時犯了一個基本錯誤?

+0

你copyied代碼工作完全正常。請確保它不是瀏覽器緩存中導致此錯誤的文件的較舊版本。 當您的googlemap javascript在使用其功能時未正確加載時,最常見的錯誤是「谷歌未定義」。 – Seybsen 2012-03-08 11:41:04

回答

0

路徑中缺少協議。

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

應該

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

(它缺少很多的例子)

+0

非常感謝你的工作。 – harbourmaster 2012-03-08 12:52:48

+1

也看到這一點 - 所以你知道**爲什麼**沒有在網址中的計劃:http://stackoverflow.com/questions/2181207/is-it-safe-to-use-schemeless-protocol-uris-on -public-網站-EX-WWW-examp – Seybsen 2012-03-12 10:36:16