LandonSchropp LandonSchropp - 1 year ago 62
Javascript Question

W3C Geolocation API not working in Chrome

The below code works in Firefox but not in Google Chrome:

<!DOCTYPE html>
<script type="text/javascript">
var successCallback = function(data) {
console.log('latitude: ' + data.coords.latitude + ' longitude: ' + data.coords.longitude);

var failureCallback = function() {
console.log('location failure :(');

var logLocation = function() {

//determine if the handset has client side geo location capabilities
navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
alert("Functionality not available");

setTimeout(logLocation, 5000);

What's going on? I thought Google Chrome was supposed to support the W3C Geolocation API.

Answer Source

Works perfectly for me - with both Chrome 11 and Firefox 4.0.1 on Win 7

  • Make sure you've not disabled location tracking in Chrome: Options > Under the Hood > Content Settings > Location
  • Because of security restrictions, resources loaded with the file:/// scheme are not allowed access to location. See HTML 5 Geo Location Prompt in Chrome.