-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (41 loc) · 1.31 KB
/
Copy pathscript.js
File metadata and controls
46 lines (41 loc) · 1.31 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
var myIcon = L.icon({
iconUrl: './images/icon-location.svg',
iconAnchor: [22, 94]
});
function giveIP(){
var userinput = document.getElementById("userinput");
setMap(userinput.value);
return false;
}
var map = null;
function setMap(query) {
if (!query)
query = "";
else
query = "?query=" + query;
fetch("https://ip-details.herokuapp.com/" + query).then((response) => {
response.json().then((details) => {
document.getElementById("ip-address").innerText = details.query;
document.getElementById("timezone").innerText = details.timezone;
document.getElementById("location").innerText = details.city + ", " + details.regionName + ", " +
details.country;
document.getElementById("isp").innerText = details.org;
let latitude = details.lat;
let longitude = details.lon;
if(!map){
map = L.map('map').setView([latitude, longitude], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
}
else{
map.setView([latitude, longitude], 12);
map.removeLayer(marker);
}
marker = L.marker([latitude, longitude], {
icon: myIcon
}).addTo(map);
})
});
}
setMap();