API of current geolocation position does not work in IE11.5 windows10
API of current geolocation position is incompatible 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 gets into an error block with response code 2 (POSITION_UNAVAILABLE) with the indication "The current position could not be determined."
In the prompt, the browser that allows the user to access the location is allowed so that this is not the reason.
Version Information
source to share
Fixed
1 - Changes described below should be added for IE only. So please check if the browser is IE if we need to add a workaround. Don't change others' browser.
2 - Change the precision of enableHighAccuracy to false. I know this is false by default, but just in case.
3 - Add some reasonable value to maximum Age for cache times. (IE only)
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);
}
Link - https://msdn.microsoft.com/en-us/library/gg593067(v=vs.85).aspx
source to share