title: Google Maps API v3 Geolocation not working in Google Chrome
body: <p>I'm using Google Maps API v3 Geolocation to get the users actual location. I found this post from Google Developers:</p>
  
  <p><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>Here my code (equals to the code of Google Maps example):</p>
  
  <pre><code>&lt;head&gt;
  &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  // 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,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
  
    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);
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="container"&gt;
          &lt;div class="entry-content"&gt;
              &lt;div class="blogtitle"&gt;IT&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
              &lt;div id="map-canvas"&gt;&lt;/div&gt;&lt;!-- map-canvas end --&gt;
          &lt;/div&gt;&lt;!-- entry-content end --&gt;
      &lt;/div&gt;&lt;!-- container end --&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>This works quite fine in Firefox but not in Google Chrome &amp; Safari. I think because Chrome &amp; Safari are webkit browsers. But I don't know how to fix it.</p>
  
  <p>Can someone please help me?</p>