title: Google Map API how to set marker for current location
body: <p>I'm learning google map API and stuck at this problem when i'm trying to add the current coordinate to an array. Here is my code:</p>
  
  <pre><code>var locations = [];
  </code></pre>
  
  <p>In initialize() i have:</p>
  
  <pre><code>function initialize() {
      infowindow = new google.maps.InfoWindow();
      var myOptions = {
          zoom: 10,
          mapTypeControl: true,
          navigationControl: true,
      }
      map = new google.maps.Map(document.getElementById("map"), myOptions);
  
      add_location('Place 1', 37.2846372, -123.3270422);
      set_current_location();
      set_markers(new google.maps.LatLngBounds(), map);
  }
  </code></pre>
  
  <p>The first marker is set, while the set_current_location() doesn't seem to work. Here is the rest of the code:</p>
  
  <pre><code>// add new location to the locations array
  function add_location(description, lastitude, longtitude) {
      locations.push([description, lastitude, longtitude]);
  }
  
  // Set all the markers in the location arrays and bound/frame the map
  function set_markers(bounds, map) {
      for (i = 0; i &lt; locations.length; i++) {
          marker = new google.maps.Marker({
              position: new google.maps.LatLng(locations[i][1], locations[i][2]),
              map: map
          });
          bounds.extend(marker.position);
          google.maps.event.addListener(marker, 'click', (function (marker, i) {
              return function () {
                  infowindow.setContent(locations[i][0]);
                  infowindow.open(map, marker);
              }
          })(marker, i));
      }
      map.fitBounds(bounds);
  }
  
  // Get current location based on the IP Address
  function set_current_location() {
      if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function (position) {
              var pos = new google.maps.LatLng(position.coords.latitude,
              position.coords.longitude);
              var myLat = position.coords.latitude;
              var myLong = position.coords.longitude;
              add_location('My location', position.coords.latitude, position.coords.longitude);
          });
      } else {
          alert("Geolocation is not supported by this browser.");
      }
  }
  </code></pre>
  
  <p>Can anyone help or give me a hint? I would like to add the current location to the locations array so I can keep track of how many locations I have added. Thank you so much.</p>