Edit Code in left box and click Show Results button to see the result. | Home
<!DOCTYPE HTML> <!-- Mirrored from www.tutorialspoint.com/cgi-bin/practice.cgi?file=html5-54.htm by HTTrack Website Copier/3.x [XR&CO'2010], Thu, 01 Sep 2011 14:43:13 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head> <script type="text/javascript"> var watchID; var geoLoc; function showLocation(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; alert("Latitude : " + latitude + " Longitude: " + longitude); } function errorHandler(err) { if(err.code == 1) { alert("Error: Access is denied!"); }else if( err.code == 2) { alert("Error: Position is unavailable!"); } } function getLocationUpdate(){ if(navigator.geolocation){ // timeout at 60000 milliseconds (60 seconds) var options = {timeout:60000}; geoLoc = navigator.geolocation; watchID = geoLoc.watchPosition(showLocation, errorHandler, options); }else{ alert("Sorry, browser does not support geolocation!"); } } function stopWatch(){ geoLoc.clearWatch(watchID); } </script> </head> <html> <body> <form> <input type="button" onclick="getLocationUpdate();" value="Watch Update"/> <input type="button" onclick="stopWatch();" value="Stop Watch"/> </form> </body> <!-- Mirrored from www.tutorialspoint.com/cgi-bin/practice.cgi?file=html5-54.htm by HTTrack Website Copier/3.x [XR&CO'2010], Thu, 01 Sep 2011 14:43:13 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html> |