I have a application which reports my location using HTML5 geolocation. The application works correct on Firefox and Chrome, but on Safari 5, it says that Safari does not su
How do you fetch Google Maps API script ? Is sensor param set to true or false ? I had Safari Geolocation not working (under Windows) until I changed "sensor=false" to "sensor=true" like the example below:
And it works perfectly in every browser : IE9, Chrome, FF10+, Safari (Win).
Noticed another strange thing - it works only with WiFi in Safari - if you wired-connected, it won't work and would just stuck trying forever.
So, to fix Safari just add the following { maximumAge: 600000, timeout: 10000 } to handle timeout :
// Try W3C Geolocation (Preferred)
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
handleGeolocationAcquired(position.coords.latitude, position.coords.longitude);
}, function(error) {
handleNoGeolocation();
},
{ maximumAge: 600000, timeout: 10000 });
// Try Google Gears Geolocation
} else if (google.gears) {
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function (position) {
handleGeolocationAcquired(position.latitude, position.longitude);
}, function () {
handleNoGeolocation();
});
}
//Cannot obtain Geo Location
else {
handleNoGeolocation();
}
This way, in case you're in Safari (under Windows) and wired-connected (=> endless loop acquiring Geo location) : after 10 seconds, it will fallback to error handler.
BTW - maximumAge param just sets location expiration.