geolocation HTML5 on firefox and chrome
I am trying out geolocation with HTML5. For some reason it works on firefox inconsistently and it does not work on chrome and throws an error called object positionerror.
2 questions
1.) How do i see the actual error (sorry I am new to javascript) 2.) Why is it working differently on chrome开发者_StackOverflow and firefox?
The script is as below -
<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 doesn't have to be hard to debug. Every reasonably modern browser has a debugger:
- Safari, Chrome, IE8+ and Firefox 4 have built-in developer tools
- For Firefox 3 and 4, there's also Firebug
As for the actual issues with using navigator.geolocation
, you might be interested in the Dive Into HTML5 Geolocation chapter.
To get to Chrome's Developer Tools, either:
Wrench -> Tools -> Developer Tools
, orView -> Developer -> Developer Tools
If you want to see the JavaScript code, add breakpoints, step through the code, etc. you'd use the Scripts
tab. The other tab I spend most of my time in is the Console
.
精彩评论