-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip-finder.js
90 lines (74 loc) · 3.32 KB
/
ip-finder.js
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
const platform = new H.service.Platform({
apikey: 'aeBu0GkfKm7QWDg1tXqpul8XcdwwzqpFljU0XxPfeiU'
});
const defaultLayers = platform.createDefaultLayers();
const map = new H.Map(
document.getElementById('map'),
defaultLayers.vector.normal.map, {
zoom: 7,
center: { lat: 12.981271, lng: 79.166130 }
}
);
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
window.addEventListener('resize', () => map.getViewPort().resize());
const ui = H.ui.UI.createDefault(map, defaultLayers);
document.getElementById('searchBtn').addEventListener('click', async () => {
const ipAddress = document.getElementById('ipInput').value;
const ipApiResponse = await fetch(`https://ipinfo.io/${ipAddress}/json`);
const ipLocationData = await ipApiResponse.json();
const [latitude, longitude] = ipLocationData.loc.split(',');
map.setCenter({ lat: parseFloat(latitude), lng: parseFloat(longitude) });
map.setZoom(14, {duration:1000});
const marker = new H.map.Marker({ lat: parseFloat(latitude), lng: parseFloat(longitude) });
map.addObject(marker);
document.getElementById('ipDetails').innerHTML = `
<p>IP: ${ipLocationData.ip}</p>
<p>Country: ${ipLocationData.country}</p>
<p>Region: ${ipLocationData.region}</p>
<p>City: ${ipLocationData.city}</p>
<p>Latitude: ${latitude}</p>
<p>Longitude: ${longitude}</p>
`;
generateQRCode(`Latitude: ${latitude}, Longitude: ${longitude}`);
});
document.getElementById('searchBtn').addEventListener('click', async () => {
const ipAddress = document.getElementById('ipInput').value;
const response = await fetch(`https://ipinfo.io/${ipAddress}/json?token=YOUR_TOKEN`);
const ipDetails = await response.json();
const [latitude, longitude] = ipDetails.loc.split(',');
const location = { lat: parseFloat(latitude), lng: parseFloat(longitude) };
const mapsUrl = `https://www.google.com/maps/search/?api=1&query=${location.lat},${location.lng}`;
updateDashboard(ipDetails);
animateMapZoom(location);
});
function animateMapZoom(location) {
map.setZoom(5, true);
setTimeout(() => {
map.setCenter(location);
map.setZoom(14, true);
}, 1000);
}
document.getElementById('searchBtn').addEventListener('click', async () => {
const ipAddress = document.getElementById('ipInput').value;
const response = await fetch(`https://ipinfo.io/${ipAddress}/json?token=YOUR_TOKEN`);
const ipDetails = await response.json();
const location = `${ipDetails.loc.split(',').join(',')}`;
const mapsUrl = `https://www.google.com/maps/search/?api=1&query=${location}`;
updateDashboard(ipDetails);
generateQR(mapsUrl);
});
document.getElementById('qrBtn').addEventListener('click', () => {
const ipAddress = document.getElementById('ipInput').value;
window.open(`qr-page.html?ip=${ipAddress}`, '_blank');
});
function updateDashboard(details) {
const dashboard = document.getElementById('ipDetails');
dashboard.innerHTML = `
<h4>IP Details</h4>
<p><strong>IP:</strong> ${details.ip}</p>
<p><strong>Country:</strong> ${details.country}</p>
<p><strong>Region:</strong> ${details.region}</p>
<p><strong>City:</strong> ${details.city}</p>
<p><strong>Latitude and Longitude:</strong> ${details.loc}</p>
`;
}