Revision: 15198
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 26, 2009 20:13 by adamdecaf
Initial Code
<!DOCTYPE html> <html> <head> <title></title> <script src="geoLocation.js"></script> <style> div#location { border: 1px solid #000000; height: 300px; margin-left: 25%; margin-top: 5%; padding: 10px 5px 10px 5px; width: 50%; } </style> </head> <body> <div id="location"> </div> <script> /** * Sample GeoLocation Script * Adam Shannon * 06/26/2009 */ function getLocation() { // First we must test to see if GeoLocation is even supported. if (navigator.geolocation) { // Now wee can start the service. // navigator.geolocation.startup(); // Check to see if the API is ready. // if (!navigator.geolocation.isReady()) { // alert("Whoops, your GeoLocation API is not currently ready"); // } // Make the call // navigator.geolocation.getCurrentPosition(success, fail, options); navigator.geolocation.getCurrentPosition(function(position) { fillDiv( position.coords.latitude, position.coords.longitude, position.coords.altitude, position.coords.accuracy, position.coords.altitudeAccuracy, position.coords.heading, position.coords.speed ); }); // Shut it down // navigator.geolocation.shutdown(); } else { alert("Whoops, it seems like your browser doesn't support GeoLocation."); } return; } function fillDiv(latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed) { // Go... // alert(latitude); // alert(longitude); var e = document.getElementById("location"); e.innerHTML = ""; e.innerHTML += "Latitude: " + latitude + "<br />"; e.innerHTML += "Longitude: " + longitude + "<br />";; e.innerHTML += "Altitude: " + altitude + "<br />";; e.innerHTML += "Accuracy: " + accuracy + "<br />";; e.innerHTML += "altitudeAccuracy: " + altitudeAccuracy + "<br />";; e.innerHTML += "Heading: " + heading + "<br />";; e.innerHTML += "Speed: " + speed; return; } // Now call getLocation(); </script> </body> </html>
Initial URL
Initial Description
This will only work in FF 3.5 and web-kit browsers after (06/26/2009)
Initial Title
JavaScript GeoLocation
Initial Tags
javascript
Initial Language
JavaScript