Created
December 13, 2012 05:57
-
-
Save juehan/4274393 to your computer and use it in GitHub Desktop.
Geolocation API in HTML5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Geolocation API in HTML5</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> | |
</script> | |
</head> | |
<body> | |
<p>Geolocation API in HTML5</p> | |
<button id="btnGeo">Show where i am</button> | |
<script type="text/javascript"> | |
var p = $('p'); | |
(function(){ | |
//callback | |
function printGeoLocation(pos){ | |
p.append("<p>Latitude: " + pos.coords.latitude + "</p>") | |
.append("<p>Longitude: " + pos.coords.longitude + "</p>") | |
.append("<p>Position accuracy: " + pos.coords.accuracy + "</p>") | |
.append("<p>Altitude: " + pos.coords.altitude + "</p>") | |
.append("<p>Heading: " + pos.coords.heading + "</p>") | |
.append("<p>Speed: " + pos.coords.speed + "</p>"); | |
} | |
$('#btnGeo').on('click', function(){ | |
if(navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(printGeoLocation); //pass callback | |
} else { | |
alert("sorry, this browser doesn't support Geolocation data"); | |
} | |
}) | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment