繁体   English   中英

IE11中的地理位置问题

[英]Issue with geolocation in IE11

我有以下代码,当用户点击/点击位置链接时,请求用户在浏览器中允许他们当前的位置。

这在Chrome,Safari和Firefox中运行良好,但我无法在IE11中使用它。 有时它会显示用户提供位置的浏览器通知,但之后没有任何反应。

我想知道是否有其他人在使用谷歌地图并在IE11中请求位置以及是否有人有解决方案?

<p id="error"></p>
<form action="/" method="post">
<a class="location-link" id="location-link" href="#"><img src="/static/images/icons/location.png" alt="Get your current location" title="Get your current location" /></a><input type="text" name="location" value="" placeholder="Find a salon" >
<input class="viewbtn3" value="Submit" type="submit"></form>
<script src="/static/js/jquery.1.9.1.js"></script>
<script src="https://maps.google.com/maps/api/js?sensor=true"></script>

<script type="text/javascript">
$(document).ready(function() {
    if (typeof navigator.geolocation == "undefined") {
        $("#error").text("Your browser doesn't support the Geolocation API");
        $(".location-instruction span").hide();
        $(".location-link").hide();
        return;
    }
    $("#location-link").click(function(event) {
        event.preventDefault();
        var addressId = this.id.substring(0, this.id.indexOf("-"));
        var thisid = $(this).attr("id");
        //console.log(thisid);
        navigator.geolocation.getCurrentPosition(function(position) {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({
                location: new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    $("#" + thisid).parent().find('input[name="location"]').val(results[0].formatted_address);
                    $(".choose_wrap").addClass('sucess');
                } else {
                    $("#" + thisid).parent().find("#error").html("Unable to retrieve your address<br />");
                    $(".choose_wrap").addClass('fail');
                }
            })
        }, function(positionError) {
            $("#" + thisid).parent().find("#error").html("Error: " + positionError.message + "<br />")
        }, {
            enableHighAccuracy: true,
            timeout: 10 * 1000
        })
    });
});
</script>

这在IE11上实际上对我有用,当我在Codepen上试用时没有任何变化:

 $(document).ready(function() { if (typeof navigator.geolocation == "undefined") { $("#error").text("Your browser doesn't support the Geolocation API"); $(".location-instruction span").hide(); $(".location-link").hide(); return; } $("#location-link").click(function(event) { event.preventDefault(); var addressId = this.id.substring(0, this.id.indexOf("-")); var thisid = $(this).attr("id"); //console.log(thisid); navigator.geolocation.getCurrentPosition(function(position) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ location: new google.maps.LatLng(position.coords.latitude, position.coords.longitude) }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { $("#" + thisid).parent().find('input[name="location"]').val(results[0].formatted_address); $(".choose_wrap").addClass('sucess'); } else { $("#" + thisid).parent().find("#error").html("Unable to retrieve your address<br />"); $(".choose_wrap").addClass('fail'); } }) }, function(positionError) { $("#" + thisid).parent().find("#error").html("Error: " + positionError.message + "<br />") }, { enableHighAccuracy: true, timeout: 10 * 1000 }) }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="https://maps.google.com/maps/api/js?sensor=true"></script> <p id="error"></p> <form action="/" method="post"> <a class="location-link" id="location-link" href="#"><img src="/static/images/icons/location.png" alt="Get your current location" title="Get your current location" /></a> <input type="text" name="location" value="" placeholder="Find a salon"> <input class="viewbtn3" value="Submit" type="submit"> </form> 

我唯一能建议的是检查开发者控制台,看看测试时是否有任何错误。

我在Windows 8上尝试了这个。如果关闭了机器上的位置设置(请参阅控制面板/更改位置设置),则会返回错误消息。 在上面的代码中“没有任何反应”。 “#error”和“#location-link”不共享同一个父级,因此该行不显示错误消息:

$("#" + thisid).parent().find("#error").html("Error: " + positionError.message + "<br />")

此问题是否阻止“地理位置未打开”消息显示在客户端计算机上?

这可能是一个Windows设置,至少在我的情况下。 尝试转到“设置”(从Windows的“开始”菜单中搜索)>“隐私”>“位置”,然后转到“位置=开”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM