-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_maps.html
95 lines (76 loc) · 3.37 KB
/
google_maps.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Geolocation con Google Maps</title>
<style type="text/css">
#mapa {
width: 100%;
height: 300px;
margin: 0;
}
</style>
</head>
<body>
<div id="mapa"></div>
<div id="datos"></div>
<a id="recarga" href="#">Recargar!</a>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=----key----"></script>
<script type="text/javascript">
((() => {
// Google Maps
google.maps.visualRefresh = true; // Refresco Constante
let map;
function initialize() {
const mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('mapa'),
mapOptions);
// Try HTML5 geolocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
const pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
const infowindow = new google.maps.InfoWindow({
map,
position: pos,
content: 'Te pille! :-)'
});
map.setCenter(pos);
//datos Primer Arranque
muestraDatos(x, position);
}, () => {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
const options = {
map,
position: new google.maps.LatLng(60, 105),
content: errorFlag ? 'Error: El Servicio de Geolocalización esta fallando.' : 'Error: Tu navegador no soporta la Geolocalización.'
};
const infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
google.maps.event.addDomListener(window, 'load', initialize);
// Datos (Core)
var x = document.getElementById("datos");
const a = document.getElementById("recarga");
function muestraDatos(div, position) {
x.innerHTML = `Latitud: ${position.coords.latitude}<br>Longitud: ${position.coords.longitude}<br>Precisión: ${position.coords.accuracy}<br>Altitud: ${position.coords.altitude}<br>Altitud Precisa: ${position.coords.altitudeAccuracy}<br>Grados Norte: ${position.coords.heading}<br>Velocidad m/s: ${position.coords.speed}<br>Última Conexión: ${position.timestamp}`;
}
//datos Actualizacion
a.onclick = (e) => {
initialize();
e.preventDefault();
};
}))();
</script>
</body>
</html>