Skip to content

Instantly share code, notes, and snippets.

@ujwalp1994
Created July 14, 2017 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujwalp1994/142604d657da045eb5381238c86d56c4 to your computer and use it in GitHub Desktop.
Save ujwalp1994/142604d657da045eb5381238c86d56c4 to your computer and use it in GitHub Desktop.
<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