The below code works in Firefox but not in Google Chrome:
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<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
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
}
else{
alert("Functionality not available");
}
};
logLocation();
setTimeout(logLocation, 5000);
</script>
</head>
<body>
<p>Testing</p>
<body>
</html>
What's going on? I thought Google Chrome was supposed to support the W3C Geolocation API.
Sites that don't use SSL can no longer access Geolocation APIs to determine a user's physical location. You can fix this by asking your host to install an SSL certificate, or by disabling the “Attempt to auto-locate the user” option on the settings page.
If an end user grants permission, the Geolocation API : Provides location data as latitude, longitude, altitude, speed, and heading, as well as the accuracy of the acquired location data, and the approximate time for when the position was acquired via the GeolocationPosition interface.
Do all browsers support the HTML5 geolocation API? HTML5 geolocation is supported by multiple browsers including Chrome, Edge, Firefox, Internet Explorer, Opera and Safari. Although you will have to check the respective versions of each browser.
The Geolocation API is accessed via a call to navigator. geolocation ; this will cause the user's browser to ask them for permission to access their location data. If they accept, then the browser will use the best available functionality on the device to access this information (for example, GPS).
Works perfectly for me - with both Chrome 11 and Firefox 4.0.1 on Win 7
Options > Under the Hood > Content Settings > Location
file:///
scheme are not allowed access to location. See HTML 5 Geo Location Prompt in Chrome.If your domain is insecure (e.g. HTTP rather than HTTPS) then you are not allowed access to location in Chrome. This is since Chrome version 50 (12PM PST April 20 2016).
See https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With