title: Add Marker - Google Maps API v3
body: <p>I have the following Javascript where I modified the standard Google Maps API initialize() function and the standard addMarker function. The map loads and centers fine, but the marker does not get added to the map.  I looked at the <a href="https://stackoverflow.com/questions/7701077/add-marker-function-with-google-maps-api">previous question</a> , but I'm not sure what I'm doing wrong..</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  // Note that using Google Gears requires loading the Javascript
  // at http://code.google.com/apis/gears/gears_init.js
  
  var siberia = new google.maps.LatLng(60, 105);
  var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687); 
  var usa = new google.maps.LatLng(44.58, -95.46); //middle of the US w 50 states     
  
  var browserSupportFlag =  new Boolean();
  
  function initialize() {
      var myOptions = {
      zoom: 4,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions)
    map.setCenter(usa);   
  }
  
  function getMyLocation() {
      var initialLocation= newyork;
      var myOptions = {
      zoom: 10,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
      // Try W3C Geolocation (Preferred)
      if(navigator.geolocation) {
          browserSupportFlag = true;
          navigator.geolocation.getCurrentPosition(function(position) {
          initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
          map.setCenter(initialLocation);
          addMarker(initialLocation);
      }, function() {
      handleNoGeolocation(browserSupportFlag);
      });
      // Try Google Gears Geolocation
      } else if (google.gears) {
          browserSupportFlag = true;
          var geo = google.gears.factory.create('beta.geolocation');
          geo.getCurrentPosition(function(position) {
          initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
          map.setCenter(initialLocation);
          addMarker(initialLocation);
      }, function() {
          handleNoGeoLocation(browserSupportFlag);
      });
      // Browser doesn't support Geolocation
      } else {
          browserSupportFlag = false;
          handleNoGeolocation(browserSupportFlag);
      }
  
      function handleNoGeolocation(errorFlag) {
          if (errorFlag == true) {
              alert("Geolocation service failed.");
              initialLocation = newyork;
          } else {
               alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
               initialLocation = siberia;
          }
          map.setCenter(usa);
      }
  
  }
  
  function addMarker(location) {
      marker = new google.maps.Marker({
      position: location,
      map: map, 
      title: "Hello World!"
      });
      //markersArray.push(marker);
  }
  &lt;/script&gt;
  </code></pre>