我正在使用地理位置,但我在识别错误时遇到了问题,无法提供替代方案。地理位置错误检测
我的HTML看起来像这样:
<button onclick="getLocation()">Get your location now</button>
<div id="google_canvas"></div>
<p id = 'error'></p>
我的剧本是这样的:
function getLocation(){
if(navigator.geolocation)
{
var map;
var mapOptions =
{
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('google_canvas'), mapOptions);
navigator.geolocation.getCurrentPosition(function(position)
{
var geolocate = new google.maps.LatLng(position.coords.latitude, position.coords.longitude),latitude=document.getElementById("latitude"),longitude=document.getElementById("longitude");
var infowindow = new google.maps.InfoWindow(
{
map: map,
position: geolocate,
content:
' * output content within map * '
});
map.setCenter(geolocate);
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
});
}
else
{
document.getElementById('error').innerHTML = 'No Geolocation Support';
}
};
google.maps.event.addListener(map, 'idle', function() {
});
我IE9的版本不支持地理位置(我试过他们的测试现场用自己的脚本),但它不会给我任何错误或警告,再加上如果我不允许在Firefox或Chrome中定位,我也不会收到任何错误或警告。
有人可以帮忙吗?如果它无法运行,我可以提供一个替代方案,所以我不认为我需要仔细查看错误代码,但我确实需要能够检测到故障,因此我可以提供替代方案,但脚本中的错误部分无论如何不会运行。
我的问题确实是,为什么不能运行?
else
{
document.getElementById('error').innerHTML = 'No Geolocation Support';
}
感谢
我没有得到错误信息,但 - 如果我这样做,这将是罚款 – user2246804
在IE9看一看底部,然后点击'允许阻止脚本...' –
对不起迈赫迪我没有得到那个错误,我承诺 – user2246804