12

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 support Geolocation.

From what I read, Safari 5 does support Geolocation. What am I missing?

Thanks for your time.

Sunil

2
  • So this wasn't solved in 6 years almost?
    – trainoasis
    Commented Mar 3, 2016 at 12:55
  • Faced the same issue, turned out I have to enable location services in Mac's System Preferences.
    – sinaza
    Commented May 15, 2018 at 19:28

5 Answers 5

21

Looks like Safari geolocation only works when connected with wifi. When connected with a wired connection Safari calls the error callback from the geolocation functions.

To test this, try this in the web console:

navigator.geolocation.getCurrentPosition(
  function(){console.log("success")},
  function(){console.log("error")}
);

With Safari/wifi this returns 'success' after a second or two, but on a wired connection it returns 'error' immediately.

( using Safari 5.1 - 8.x / Mac OSX 10.7 - 10.10 )

4
  • 1
    Thanks Andy. I tried it over Wi fi and the geolocation worked well on Safari. Commented Jul 28, 2011 at 1:45
  • 1
    There may be something more going on here. Yesterday this was the case, but today I am getting 'success' on my wired connection. All I can remember changing is installing the developer tools.
    – andyvanee
    Commented Jul 29, 2011 at 16:12
  • There is definitely something going on here. Using Safari 5.1 (also happened with previous version), sometimes Geolocation works, sometimes not at all. Usually get a timeout error. With absolutely no changes to my system. But I have no idea what the problem might be. All other browsers seem to work perfectly. Commented Jul 29, 2011 at 17:51
  • Does anyone else notice @andyvanee 's problem with developer tools?
    – user393219
    Commented Aug 26, 2015 at 20:24
3

Although nominally geolocation support in Safari 5 is available on both Mac and Windows, I'm hearing of more issues on the Windows side.

For example, see this similar StackOverflow question. In that case, though, navigator.geolocation was available, it just never received a successful callback. When you say that "it says that Safari does not support Geolocation", who is saying that to you? Are you getting an error callback, is navigator.geolocation null, or have you just read this elsewhere (and if so, where?)?

9
  • 1
    It may be that the user has disabled geolocation features. Commented Sep 25, 2010 at 2:16
  • Yes, that is one possibility, in which case I believe that navigator.geolocation should be null.
    – npdoty
    Commented Sep 25, 2010 at 4:30
  • i have a javascript alert setup for cases when geolocation is not available. Chrome and Firefox do not trigger this alert. Only Safari 5 does. Commented Sep 25, 2010 at 6:43
  • 2
    @Sunil That might suggest that Location services are disabled: can you check in your Safari settings? (On a Mac, Safari > Preferences > Security > Location services; should be similar on Windows.) And Firefox and Chrome are returning correct locations on the same machine?
    – npdoty
    Commented Sep 26, 2010 at 8:23
  • 1
    @SunilShenoy did they fix it? Obviously not - Safari and iOS not working for me..
    – trainoasis
    Commented Mar 3, 2016 at 12:49
3

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:

<script src="http://maps.googleapis.com/maps/api/js?sensor=true" type="text/javascript"></script>

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.

1
  • Not working for me. I'm using async and defer to load the script (i need autosuggest and other apis also..) and Safari no-go ...
    – trainoasis
    Commented Mar 3, 2016 at 12:48
2

hmmm, I'm a little stumped. Safari 5 does support geolocation through HTML 5. You might want to try to use an HTML 5 feature detection service like Modernizr. This will tell you what browsers support html5 and css3 standards. I'm using Safari 5 and Modernizr shows that the geolocation API is supported.

1
  • Geolocation API is supported but it does not work on Safari.
    – trainoasis
    Commented Mar 3, 2016 at 12:49
1

Calling getCurrentPosition(...) without specified timeout makes Safari stuck there for minutes.

1
  • It does not work even with given timeout (safari only)
    – trainoasis
    Commented Mar 3, 2016 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.