With the latest iOS update (10.3, is working with 10.2 - I tested this with multiple devices), Geolocation.now
stopped working with default options. Don't know how long this hasn't been working with macOS Sierra, but it certainly doesn't work with 10.12.5. Geolocation.now
with default options works in Chrome desktop and mobile, but in Safari it fails.
The cause of the problem is with the default options and the timeout setting:
function fromOptions(options)
{
return {
enableHighAccuracy: options.enableHighAccuracy,
timeout: options.timeout._0 || Infinity,
maximumAge: options.maximumAge._0 || 0
};
}
Having timeout = Infinity immediately returns an error in the latest Safari across all platforms. In all the newest versions of Safari, this works exactly the same as passing timeout "0".
This can be tested easily by this snippet:
navigator.geolocation.getCurrentPosition(() => {}, (err) => { console.log(err)}, { timeout: Infinity})
It outputs just the next moment:
[Log] PositionError {code: 3, message: "Timeout expired", PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
Note that not passing any options works just fine with Safari and every other browser I tested:
navigator.geolocation.getCurrentPosition((result) => {console.log(result)}, (err) => { console.log(err)})
[Log] Geoposition {coords: Coordinates, timestamp: 519569198545}
I've checked MDN documentation once again (https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) and it does say that default option for timeout is Infinity. Seems like Apple decided to do something differently.
Anyway, with current implementation, unspecified (default) options just break the Geolocation API. Is it possible not to pass timeout set to Inifinity when talking to JS?