-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (41 loc) · 1.22 KB
/
Copy pathscript.js
File metadata and controls
48 lines (41 loc) · 1.22 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
var mapLat;
var mapLng;
var map;
function updateMap(){
if(map != undefined){
map.remove();
}
map = L.map('map').setView([mapLat, mapLng], 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([mapLat, mapLng]).addTo(map)
.bindPopup(`<span>Lat: ${mapLat}</span><br><span>Lng: ${mapLng}</span>`)
.openPopup();
}
function updateAddress(data){
console.log(data);
mapLat=data.location.lat;
mapLng=data.location.lng;
$('#ip-value').html(data.ip);
$('#location-value').html(data.location.city+", "+data.location.region);
$('#timezone-value').html(data.location.timezone);
$('#isp-value').html(data.isp);
updateMap();
}
function updateChanges(){
$.ajax({
url: "https://geo.ipify.org/api/v1",
method: "GET",
success: updateAddress,
data: {
apiKey: "at_77upRBzcEy8oYSVcYzdvjzTiGygaI",
ipAddress: $('#ip-address-value').val(),
}
});
}
updateChanges();
$('.search-bar-icon').click(function(event){
event.preventDefault();
updateChanges();
});