Geolocation current position API is inconsistent in IE11 windows 10 machine. Below is the code
function setCurrentPos(event, firstLoad) {
navigator.geolocation.getCurrentPosition(function (position) {
firstLoad || setCurrentLocation(event.target, position.coords);
}, function (error) {
1 === error.code && ($this.currentLocDenied = !0);
});
}
4 out of 5 times it is falling into the error block with response code 2(POSITION_UNAVAILABLE) stating "The current position could not be determined.".
The browser prompt that appears to allow user to access location is set to allow so that should not be the reason.
Version Info
Any other suggestions??
Fixed
1 – Changes that I described below should be added only for IE. So please check if the browser is IE if we need to add a workaround. Do not change the others browser.
2 – Change the accuracy of enableHighAccuracy to false. I know that is false by default but just in case.
3 – Add some reasonable value on the maximumAge for the cache time. (Just for IE)
var locationOptions = {};
if(deviceInfo.raw.browser.isIE && parseInt(deviceInfo.browser_version) == 11 && deviceInfo.os.isWindows10) {
locationOptions = {
enableHighAccuracy: false,
maximumAge: 50000
}
}
function setCurrentPos(event, firstLoad) {
navigator.geolocation.getCurrentPosition(function (position) {
//success callback
}, function (error) {
//error callback
}, locationOptions);
}
Reference - https://msdn.microsoft.com/en-us/library/gg593067(v=vs.85).aspx
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