geoLocation.GetCurrentPosition在IE 11中总是失败 [英] geoLocation.GetCurrentPosition always fails in IE 11
问题描述
下面的脚本在FireFox和Chrome中运行良好,但在Internet Explorer 11中,它总是失败(使用POSITION_UNAVAILABLE)。
我已经将浏览器设置为允许请求我同意浏览器在请求许可时给我提示。
我几乎可以肯定,这在几个月前我最后一次实验时运行良好用它。我可以错过IE的设置吗?
< script type =text / javascript>
$(document).ready(function(){
if(Modernizr.geolocation)
{
navigator.geolocation.getCurrentPosition(positionSuccess,positionError,{enableHighAccuracy:true,maximumAge :60000,timeout:10000})
}
else
{
$(#GeoError)。html(Unable to retrieve current position。)
}
});
function positionSuccess(position)
{
$(#Latitude)。val(position.coords.latitude);
$(#Longitude)。val(position.coords.longitude);
}
函数positionError(错误)
{
var message =;
//检查已知错误
switch(error.code){
case error.PERMISSION_DENIED:
message =本网站没有您的使用许可地理定位API;
休息;
case error.POSITION_UNAVAILABLE:
message =您目前的位置无法确定。;
休息;
case error.PERMISSION_DENIED_TIMEOUT:
message =您的当前位置无法在指定的超时期限内确定。
休息;
}
//如果这是一个未知的错误,请构建一条消息,其中包含
//有助于识别情况的信息,以便
//错误处理程序可以更新。
if(message ==){
var strErrorCode = error.code.toString();
message =由于+
未知错误(代码:+ strErrorCode +),您的位置无法确定。
$(#GeoError)。html(消息)
}
< / script>
另外,当我尝试 http://html5demos.com/geo ,其中FireFox和Chrome都可以正常工作。 解决方案
您是否启用位置服务?
我有同样的问题,它在我启用了位置服务。
The script below works fine in FireFox and Chrome, but in Internet Explorer 11, it always fails (with POSITION_UNAVAILABLE).
I have set the browser to allow requests for position, and I agree to the prompt the browser presents me when requesting permission.
I'm almost certain that this worked fine a few months ago when I was last experimenting with it. What could I be missing as far as IE's settings?
<script type="text/javascript">
$(document).ready(function () {
if (Modernizr.geolocation)
{
navigator.geolocation.getCurrentPosition(positionSuccess, positionError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 10000 })
}
else
{
$("#GeoError").html("Unable to retrieve current position.")
}
});
function positionSuccess(position)
{
$("#Latitude").val(position.coords.latitude);
$("#Longitude").val(position.coords.longitude);
}
function positionError(error)
{
var message = "";
// Check for known errors
switch (error.code) {
case error.PERMISSION_DENIED:
message = "This website does not have your permission to use the Geolocation API";
break;
case error.POSITION_UNAVAILABLE:
message = "Your current position could not be determined.";
break;
case error.PERMISSION_DENIED_TIMEOUT:
message = "Your current position could not be determined within the specified timeout period.";
break;
}
// If it's an unknown error, build a message that includes
// information that helps identify the situation, so that
// the error handler can be updated.
if (message == "") {
var strErrorCode = error.code.toString();
message = "Your position could not be determined due to " +
"an unknown error (Code: " + strErrorCode + ").";
}
$("#GeoError").html(message)
}
</script>
Also, I get the same failure in IE11 when I try http://html5demos.com/geo, where both FireFox and Chrome work fine.
Does you enable the Location Service?
I have had the same issue, it worked after I enabled the Location Service in my windows 2016.
This page shows how to enable the Location Service in windows 10.
这篇关于geoLocation.GetCurrentPosition在IE 11中总是失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!