【发布时间】:2015-01-25 19:15:37
【问题描述】:
我有以下代码,当用户单击/点击位置链接时,请求用户在浏览器中允许他们当前的位置。
这在 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和Windows 10?
-
是的,我尝试过 IE11,但它只有一个边距设置问题。地理位置没有问题
标签: javascript google-maps internet-explorer geolocation