简体   繁体   中英

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 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 , or
  • View -> 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM