<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function htmlonload(){
if (window.navigator.geolocation) {
navigator.geolocation.watchPosition(successCallback, errorCallback);
} else {
alert("Sorry! your browser does not support Geolocation API.");
}
}
function successCallback(position){
var msg ="";
msg += "Latitude: " + position.coords.latitude + "<br/>";
msg += "Longitude: " + position.coords.longitude + "<br/>";
msg += "Accuracy: " + position.coords.accuracy + "<br/>";
msg += "@" + position.timestamp;
changeText("MyText", "My Location: " + msg);
}
function errorCallback(error) {
changeText("MyText", "Error: " + error);
}
function changeText(id, text){
document.getElementById(id).innerHTML = text;
}
</script>
<meta charset="UTF-8">
<title>Simple Geolocation API demo</title>
</head>
<body onload="htmlonload();">
<h1>Simple Geolocation API demo</h1>
<div id="MyText">Waiting...</div>
</body>
</html>
Related post:
- Tracking my location on mobile web with Google Map
No comments:
Post a Comment