Information Technology Reference
In-Depth Information
Listing 9-3. Geolocation checkin example
<html>
<head>
<title>Android Web Application Development-Geolocation example 3</title>
<script type="text/javascript">
function supportsGeo () {
if (navigator.geolocation) {
return true;
} else {
return false;
}
}
function changeDiv (name, data) {
var div = document.getElementById(name);
if(div)
{
div.innerHTML = data;
}
}
function checkIn () {
var geoData = "";
if (supportsGeo()) {
navigator.geolocation.getCurrentPosition(function(position) {
geoData = position.coords.latitude + ", " +
position.coords.longitude;
});
<!-- alert("Confirm geolocation access before clicking OK"); -->
} else {
geoData = "Your browser does not support HTML5 geolocation";
}
changeDiv ("myCheckIn",geoData);
}
</script>
</head>
<body>
<h1>
<div id="myCheckIn">
<!-- This is where your check-in will display -->
<p>Ready to check in...</p>
</div>
<form name="checkInFrm">
<input type="button" name="checkInBtn" value="Geolocation Check-In!"
onClick="checkIn()">
</h1>
</body>
</html>
Let's break this down into four parts, so you can digest what's happening, and also
tinker and change the code yourself so you can explore possibilities as we go.
 
Search WWH ::




Custom Search