title: Google Maps JS API Geolocation Permission Denied
body: <p>I'm using the Geolocation function to attempt to find the user's device via HTML5 as provided here:
  <a href="https://developers.google.com/maps/documentation/javascript/examples/map-geolocation" rel="nofollow">https://developers.google.com/maps/documentation/javascript/examples/map-geolocation</a></p>
  
  <p>Everything works great if the user accepts the prompt, but I would like to provide an alternate set of LatLng coordinates if the user denies permission. Currently (including Google's example linked above) if the user denies permission, it renders a blank space where the map should be.</p>
  
  <p>So if the user accepts, render map centered at their location, and if the user denies permission, render map centered at an alternate geopoint.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Note: This example requires that you consent to location sharing when
  // prompted by your browser. If you see a blank space instead of the map, this
  // is probably because you have denied permission for location sharing.
  
  var map;
  
  function initialize() {
    var mapOptions = {
      zoom: 6
    };
    map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);
  
    // Try HTML5 geolocation
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);
  
        var infowindow = new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: 'Location found using HTML5.'
        });
  
        map.setCenter(pos);
      }, function() {
        handleNoGeolocation(true);
      });
    } else {
      // Browser doesn't support Geolocation
      handleNoGeolocation(false);
    }
  }
  
  function handleNoGeolocation(errorFlag) {
    if (errorFlag) {
      var content = 'Error: The Geolocation service failed.';
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.';
    }
  
    var options = {
      map: map,
      position: new google.maps.LatLng(60, 105),
      content: content
    };
  
    var infowindow = new google.maps.InfoWindow(options);
    map.setCenter(options.position);
  }
  
  google.maps.event.addDomListener(window, 'load', initialize);</code></pre>
  </div>
  </div>
  </p>