-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (50 loc) · 2.16 KB
/
index.js
File metadata and controls
57 lines (50 loc) · 2.16 KB
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
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
var coordenadas = document.getElementById('cordenada')
var altitud = document.getElementById('altura')
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
coordenadas.innerHTML = crd.latitude + ',' + crd.longitude
altitud.innerHTML = crd.accuracy + ' Mts.'
loadUbication(crd.latitude,crd.longitude)
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
ubicacion.innerHTML = err.code + ' - - -' + err.message;
};
navigator.geolocation.getCurrentPosition(success, error, options);
function myMap(latitu,logitu) {
var mapProp= {
center:new google.maps.LatLng(latitu,logitu),
zoom:5,
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
function loadUbication(latitu,logitu) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var ubicacion = document.getElementById('ubicacion')
console.log(this.response.results);
console.log(JSON.parse(this.response));
var localidad = JSON.parse(this.response)
console.log(localidad['results'][0]['address_components'][0]['long_name']);
console.log(localidad['results'][1]['address_components'][0]['long_name']);
console.log(localidad['results'][2]['address_components'][0]['long_name']);
localizacion_1 = localidad['results'][0]['address_components'][0]['long_name']
localizacion_2 = localidad['results'][1]['address_components'][0]['long_name']
localizacion_3 = localidad['results'][2]['address_components'][0]['long_name']
ubicacion.innerHTML = localizacion_1 + ', ' + localizacion_2 + ', ' + localizacion_3;
myMap(latitu,logitu)
}
};
xhttp.open("GET", `https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitu},${logitu}&key=AIzaSyDN79kG4OiJYPvpcJfFout7Kg5BS_g4trM`, true);
xhttp.send();
}