Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18849

This is an exampe that I have copied that should work but give error

From "Tony" <tony.johansson@inport.com>
Newsgroups comp.lang.javascript
Subject This is an exampe that I have copied that should work but give error
Date 2013-03-12 17:41 +0100
Organization A noiseless patient Spider
Message-ID <khnlo6$362$1@dont-email.me> (permalink)

Show all headers | View raw


This is a copy example that should work but this line
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
give this error
runtime error in JavaScript: It's not possible to get property undefined for 
a reference that is undefined or null.

Below is the complete example.
What is it that I have missed here ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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"/>
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  <script type="text/javascript">
      google.load("maps", "2", { "other_params": "sensor=false" });

      function init()
      {
         map = new google.maps.Map2(document.getElementById("map"));
         var myLatLng = new google.maps.LatLng(54.124634, -3.237029);
         var myMarker = new google.maps.Marker(myLatLng, { "draggable": 
"true", "title": "A place on earth" });
         map.setCenter(myLatLng, 17);
         map.addControl(new google.maps.LargeMapControl());
         map.addControl(new google.maps.MapTypeControl());
         map.setMapType(G_SATELLITE_MAP);
         map.addOverlay(myMarker);

         var homeControlDiv = document.createElement('div');
         var homeControl = new HomeControl(homeControlDiv, map);

         homeControlDiv.index = 1;
         map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
      };


      function HomeControl(controlDiv, map)
      {
          // Set CSS styles for the DIV containing the control
          // Setting padding to 5 px will offset the control
          // from the edge of the map.
          controlDiv.style.padding = '5px';

          // Set CSS for the control border.
          var controlUI = document.createElement('div');
          controlUI.style.backgroundColor = 'white';
          controlUI.style.borderStyle = 'solid';
          controlUI.style.borderWidth = '2px';
          controlUI.style.cursor = 'pointer';
          controlUI.style.textAlign = 'center';
          controlUI.title = 'Click to set the map to Home';
          controlDiv.appendChild(controlUI);

          // Set CSS for the control interior.
          var controlText = document.createElement('div');
          controlText.style.fontFamily = 'Arial,sans-serif';
          controlText.style.fontSize = '12px';
          controlText.style.paddingLeft = '4px';
          controlText.style.paddingRight = '4px';
          controlText.innerHTML = '<strong>Home</strong>';
          controlUI.appendChild(controlText);

          var chicago = new google.maps.LatLng(41.850033, -87.6500523);
          // Setup the click event listeners: simply set the map to Chicago.
          google.maps.Event.addDomListener(controlUI, 'click', function ()
          {
              map.setCenter(chicago)
          });
      }
      google.setOnLoadCallback(init);
  </script>
  <title>My first Google Map</title>
</head>
<body onunload="google.maps.Unload()">
  <div id="map" style="width: 800px; height: 800px; margin: auto; 
background-color: red">
    This is where the map will soon appear.
  </div>
</body>
</html>

//Tony 

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

This is an exampe that I have copied that should work but give error "Tony" <tony.johansson@inport.com> - 2013-03-12 17:41 +0100
  Re: This is an exampe that I have copied that should work but give error Gregor Kofler <usenet@gregorkofler.com> - 2013-03-12 17:45 +0100
  Re: This is an exampe that I have copied that should work but give error JJ <jaejunks@nah.meh> - 2013-03-12 18:17 +0000

csiph-web