1

I am just getting started with the Maps API and I was trying to copy the following example.

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

When I copy the source I get the following error in the script.

google is not defined Line 11 var fenway = new google.maps.LatLng(42.345573,-71.098326);

This is the html file I am using.

<!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>

The google example loads perfectly but my code does not.

I have seen a few people getting this error but none of the fixes listed seem to work for me. Have I just made a basic error while copying the script?

  • Your copyied code works perfectly fine. Please ensure that it is not a older version of the file you have in browser cache which is causing this error. The error `google is not defined` is most common when your googlemap javascript did not load correctly when using its functions. – Seybsen Mar 08 '12 at 11:41

1 Answers1

0

There is the protocol missing in the path.

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

should be

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

(it's missing in many of the examples)

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • 1
    also see this - so you know **why** there is no scheme in the URLs: http://stackoverflow.com/questions/2181207/is-it-safe-to-use-schemeless-protocol-uris-on-public-websites-ex-www-examp – Seybsen Mar 12 '12 at 10:36