<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
#mapa {
height: 100%;
position:inherit!important;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<title>Geolocalizar tu ubicación en Google Maps</title>
<script>
function drawMap(position) {
const myLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
const mapOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
let map = new google.maps.Map(document.getElementById('mapa'), mapOptions);
// definimos la marca
const marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Tu ubicación"
});
}
function initialize(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(drawMap);
} else {
alert("La Geolocalización no esta soportada en este navegador.");
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<h1>Geolocalizar tu ubicación en Google Maps</h1>
<div id="mapa"></div>
</body>
</html>
Comentarios sobre la versión: 1 (0)
No hay comentarios