Created
November 28, 2011 08:37
-
-
Save skhatri/1399637 to your computer and use it in GitHub Desktop.
geolocation
This file contains 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
<html> | |
<head> | |
<title>Geo</title> | |
<script> | |
window.addEventListener('load', function() { | |
if (navigator.geolocation) { | |
var pos = document.getElementById("pos"); | |
navigator.geolocation.getCurrentPosition( | |
function(position) { | |
var pt = position.coords; | |
pos.innerHTML = "we tracked you at " + pt.latitude + ", " + pt.longitude+", " + pt.accuracy; | |
var img = document.createElement("img"); | |
img.src = "http://maps.googleapis.com/maps/api/staticmap?center="+pt.latitude+","+pt.longitude+"&zoom=16&size=500x500&sensor=false&markers=color:blue%7Clabel:S%7C"+pt.latitude+","+pt.longitude; | |
document.body.appendChild(img); | |
var smg = document.createElement("img"); | |
smg.src = "http://maps.googleapis.com/maps/api/streetview?size=500x500&location="+pt.latitude+",%20"+pt.longitude+"&heading=235&sensor=false"; | |
document.body.appendChild(smg); | |
}, | |
function(error) { | |
var errorType={ | |
1: 'Permission Denied', | |
2: 'Position is not available', | |
3: 'Request timeout' | |
}; | |
pos.innerHTML = 'Location error: ' + errorType[error.code]; | |
}, | |
{ | |
enableHighAccuracy: true, | |
timeout: 10000, | |
maximumAge: 0 | |
} | |
); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="pos"/> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment