title: Google Maps JavaScript API Autocomplete with Current Location Option
body: <p>I'm using the Google Maps JavaScript API with Autocomplete.</p>
  
  <p>I would like to add an option (that appears as the first menu option before the Google-generated autocomplete options) for the user's current location:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="text" name="address" id="address" placeholder="Start: Your Location" /&gt;
  &lt;div id="map"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>var map;
  
  function initMap() {
  
    var input = document.getElementById('address');
    var autocomplete = new google.maps.places.Autocomplete(input);
  
    map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: -34.397, lng: 150.644},
        zoom: 8
    });
  
  }
  
  function getCurrentLocation() {
  
      // Try HTML5 geolocation
  
      if (navigator.geolocation) {
  
          navigator.geolocation.getCurrentPosition(function(position) {
  
              var pos = {
                  lat: position.coords.latitude,
                  lng: position.coords.longitude
              };
  
              var location  = new google.maps.LatLng(pos['lat'], pos['lng']);    // turn coordinates into an object
  
              geocoder.geocode({'latLng': location}, function (results, status) {
  
                  if(status == google.maps.GeocoderStatus.OK) {
  
                      // Add option as first option in autocomplete display
  
                   }
  
              });
  
          }, function() {
  
          });
  
      } else {
  
          console.log('could not get your location.');
  
          // Browser doesn't support Geolocation
  
      }
  
      function handleLocationError(browserHasGeolocation, infoWindow, pos) {
          infoWindow.setPosition(pos);
          infoWindow.setContent(browserHasGeolocation ?
              'Error: The Geolocation service failed.' :
              'Error: Your browser doesn\'t support geolocation.');
      }
  
  }
  </code></pre>
  
  <p>Here is the <a href="https://jsfiddle.net/9rf9qa47/1/" rel="nofollow">jsfiddle</a> showing the map and autocomplete.</p>