Skip to content

Instantly share code, notes, and snippets.

@evilnapsis
Created March 27, 2018 16:31
Show Gist options
  • Save evilnapsis/66f9236977fec489c76fd686e3ae0640 to your computer and use it in GitHub Desktop.
Save evilnapsis/66f9236977fec489c76fd686e3ae0640 to your computer and use it in GitHub Desktop.
Obtener ubicacion y mostrarla en un mapa
<!-- Powered by Evilnapsis at http://evilnapsis.com/ -->
<!DOCTYPE html>
<html>
<head>
<title>Obtener ubicacion</title>
</head>
<body>
<h1>Obtener ubicacion y mostrarla en un mapa</h1>
<div id="map" style="width:100%;height:600px;"></div>
<script>
navigator.geolocation.getCurrentPosition(function(location) {
console.log(location.coords.latitude);
console.log(location.coords.longitude);
var map;
var center = {lat: location.coords.latitude, lng: location.coords.longitude};
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: center,
zoom: 6
});
var marker = new google.maps.Marker({
position: {lat: location.coords.latitude, lng: location.coords.longitude},
map:map,
title: 'Ubication'
});
}
initMap();
});
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDuBEidKGDuQo7Bzf1uRg47MPaRRlEesw0">
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment