Created
July 14, 2017 12:02
-
-
Save ujwalp1994/142604d657da045eb5381238c86d56c4 to your computer and use it in GitHub Desktop.
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> | |
<script type="text/javascript"> | |
function geoFindMe() { | |
var output = document.getElementById("out"); | |
if (!navigator.geolocation){ | |
output.innerHTML = "<p>Geolocation is not supported by your browser</p>"; | |
return; | |
} | |
function success(position) { | |
var latitude = position.coords.latitude; | |
var longitude = position.coords.longitude; | |
output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>'; | |
var img = new Image(); | |
img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false"; | |
output.appendChild(img); | |
}; | |
function error() { | |
output.innerHTML = "Unable to retrieve your location"; | |
}; | |
output.innerHTML = "<p>Locating…</p>"; | |
navigator.geolocation.getCurrentPosition(success, error); | |
} | |
</script> | |
</head> | |
<body class="body"> | |
<input type="button" value="submit" name="submit" onclick="geoFindMe()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment