title: Google Maps Javascript GeoLocation - Not working on Chrome
body: <p>Note: The original source for the html quoted below came from <a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_map" rel="nofollow noreferrer">http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_map</a> and <a href="https://stackoverflow.com/questions/5363811/google-maps-javascript-v3-geolocation-cannot-access-initiallocation-variable-u">Google Maps Javascript V3 geolocation - cannot access initialLocation variable unless alerted</a></p>
  
  <p>I've gathered three different versions of geolocation examples. All work properly in Firefox. None work in Chrome. I've set the Chrome permission to allow all sites to use my location, but still no success. It must be a Chrome setting, but not the obvious one: Settings/Show Advanced Settings/Privacy/Content Settings/Location/Allow all sites to track my physical location.</p>
  
  <p>In Firefox I see my current location after being prompted to Share Location.</p>
  
  <p>In Chrome I get User denied the request for Geolocation or 
  Error: The Geolocation service failed depending on the html.</p>
  
  <p>Given that is works in Firefox and not Chrome I figure it has to be a Chrome setting, but I just don't know what I can do that is more permissive than Allow all sites to track my physical location.</p>
  
  <p>Here are the three HTML5 files:</p>
  
  <h1>geoGoogle.html:</h1>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
     &lt;title&gt;Geolocation&lt;/title&gt;
     &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"&gt;
     &lt;meta charset="utf-8"&gt;
     &lt;link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet"&gt;
     &lt;!--
     Include the maps javascript with sensor=true because this code is using a
     sensor (a GPS locator) to determine the user's location.
     See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
     --&gt;
     &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true"&gt;&lt;/script&gt;
  
     &lt;script&gt;
  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) {
            initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
            map.setCenter(initialLocation);
            var infowindow = new google.maps.InfoWindow({
              map: map,
              position: initialLocation ,
              content: 'Location found using W3C standard'
            });
            var marker = new google.maps.Marker({
              position: initialLocation, 
              map: map
            });
          }, 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="map-canvas"&gt;&lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h1>geoGoogle2.html:</h1>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
     &lt;title&gt;Geolocation&lt;/title&gt;
     &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"&gt;
     &lt;meta charset="utf-8"&gt;
     &lt;link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet"&gt;
     &lt;!--
     Include the maps javascript with sensor=true because this code is using a
     sensor (a GPS locator) to determine the user's location.
     See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
     --&gt;
     &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true"&gt;&lt;/script&gt;
  
     &lt;script&gt;
  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="map-canvas"&gt;&lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h1>geoGoogle3.html:</h1>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;p id="demo"&gt;Click the button to get your position:&lt;/p&gt;
  &lt;button onclick="getLocation()"&gt;Try It&lt;/button&gt;
  &lt;div id="mapholder"&gt;&lt;/div&gt;
  &lt;script&gt;
  var x=document.getElementById("demo");
  function getLocation()
    {
    if (navigator.geolocation)
      {
      navigator.geolocation.getCurrentPosition(showPosition,showError);
      }
    else{x.innerHTML="Geolocation is not supported by this browser.";}
    }
  
  function showPosition(position)
    {
    var latlon=position.coords.latitude+","+position.coords.longitude;
  
    var img_url="http://maps.googleapis.com/maps/api/staticmap?center="
    +latlon+"&amp;zoom=14&amp;size=400x300&amp;sensor=false";
    document.getElementById("mapholder").innerHTML="&lt;img src='"+img_url+"'&gt;";
    }
  
  function showError(error)
    {
    switch(error.code) 
      {
      case error.PERMISSION_DENIED:
        x.innerHTML="User denied the request for Geolocation."
        break;
      case error.POSITION_UNAVAILABLE:
        x.innerHTML="Location information is unavailable."
        break;
      case error.TIMEOUT:
        x.innerHTML="The request to get user location timed out."
        break;
      case error.UNKNOWN_ERROR:
        x.innerHTML="An unknown error occurred."
        break;
      }
    }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks</p>