2

I am trying to get the user location via

navigator.geolocation.getCurrentPosition(this.check_location.bind(this), this.on_get_position_error.bind(this), { enableHighAccuracy: true, timeout: 5000 });

it works perfectly most of the time. But if the geolocation is disabled in the device settings (for example on iPhone : Settings App > Privacy > Location services > OFF), Safari or Chrome won't call any callback (neither this.check_location() nor this.on_get_position_error()).

Any idea ?

Thanks

kharlamm
  • 41
  • 4
  • Yuo might be interested in this answer http://stackoverflow.com/questions/6092400/is-there-a-way-to-check-if-geolocation-has-been-declined-with-javascript – Dinca Adrian May 11 '17 at 08:11

1 Answers1

2

Ok so i fixed it. I don't understand why but adding a 0-delay timeout makes it work :

setTimeout(function() {

navigator.geolocation.getCurrentPosition(this.check_location.bind(this), this.on_get_position_error.bind(this), { enableHighAccuracy: true, timeout: 5000 });

}.bind(this), 0);
kharlamm
  • 41
  • 4