我正在尝试使用HTML5进行地理位置定位。由于某种原因,它不能在Firefox上正常工作,不能在chrome上工作,并抛出称为对象positionerror的错误。
2个问题
1.)我如何看到实际错误(对不起,我是javascript新手)
2.)为什么在chrome和firefox上工作不同?
脚本如下-
<script>
if(!navigator.geolocation) {
alert ('your browser sux');
} else {
navigator.geolocation.getCurrentPosition(success, error);
}
function success(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
document.write(lat + ', ' + lng);
}
function error(error) {
alert ('damn error' +error);
}
最佳答案
JavaScript不必很难调试。每个合理的现代浏览器都有调试器:
Safari,Chrome,IE8 +和Firefox 4具有内置的开发人员工具
对于Firefox 3和4,还有Firebug
至于使用navigator.geolocation
的实际问题,您可能对Dive Into HTML5 Geolocation chapter感兴趣。
要使用Chrome的开发者工具,请执行以下任一操作:Wrench -> Tools -> Developer Tools
,或View -> Developer -> Developer Tools
如果要查看JavaScript代码,添加断点,逐步执行代码等,则可以使用Scripts
选项卡。我大部分时间都在使用的另一个标签是Console
。
关于javascript - 在Firefox和Chrome上进行HTML5地理定位,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6010937/