location nearby html code example
Example: location nearby html
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Reports</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="google" value="notranslate" />
<meta name="application-name" content="GeoLocator" />
<meta name="description" content="HTML5's approach to email" />
<meta name="application-url" content="https://developer.mozilla.org" />
<meta name="google" content="notranslate" />
<script type="text/javascript">
<![CDATA[
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
var x = null;
function success(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var accuracyInMeters = position.coords.accuracy;
x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
}
function error(err)
{
console.warn('ERROR(' + err.code + '): ' + err.message);
x.innerHTML = '<span style="color: red;">No fix on location</span>';
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error, options);
} else {
alert("not supported")
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
document.addEventListener('DOMContentLoaded', function ()
{
x = document.getElementById("demo");
getLocation();
})
]]>
</script>
<style type="text/css" media="all">
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="demo"></div>
</body>
</html>