-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPMap.js
More file actions
74 lines (56 loc) · 2.18 KB
/
IPMap.js
File metadata and controls
74 lines (56 loc) · 2.18 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//INIZIA CODICE PER MAPPE/
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup('You are HERE!!')
.openPopup();
//ELEMENTI INFORMAZIONE IP//
const Address = document.getElementById("address");
let Location = document.getElementById("location");
const timeZone = document.getElementById("timezone");
const ISP = document.getElementById("isp");
let Input = document.getElementById("input");
//PULSANTE RICERCA IP//
const button = document.getElementById("button");
//MOSTRA L'INDIRIZZO IP DELL'UTENTE CHE ACCEDE//
function getIP() {
let CurrentApi = 'https://api.ipify.org?format=json';
fetch(CurrentApi)
.then(response => response.json())
.then(data => {
Input.value = data.ip;
console.log(data);
RunIp();
});
}
getIP();
//TI PERMETTE DI CERCARE UN INDIRIZZO IP SCRIVENDOLO NELLA BARRA DI RICERCA//
function RunIp() {
let Api = `https://geo.ipify.org/api/v2/country,city?apiKey=at_qT6MiqNooGzdQTMbp5iDqTP7sefha&ipAddress=${Input.value}`;
fetch(Api)
.then(response => response.json())
.then(data => {
console.log(data);
Address.innerHTML = data.ip;
Location.innerHTML = data.location.city;
timeZone.innerHTML = "UTC" + " " + data.location.timezone;
ISP.innerHTML = data.isp;
L.marker([data.location.lat, data.location.lng]).addTo(map)
.bindPopup('You are in' + " " + `${data.as.name}`)
.openPopup();;
map.setView([data.location.lat, data.location.lng]);
});
}
//SEMPLICE PULSANTE CHE AVVIA LA RICERCA DELLE INFORMAZIONI DELL'IP INSERITO//
button.addEventListener("click", () => {
RunIp();
})
//RICERCA ABILITATA CON IL CLICK DEL TASTO "ENTER"//
Input.addEventListener("keydown", (e) => {
if (e.keyCode === 13) {
RunIp();
e.preventDefault();
}
})