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 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:
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 ToolsIf you want to see the JavaScript code, add breakpoints, step through the code, etc. you’d use the
Scriptstab. The other tab I spend most of my time in is theConsole.