-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (31 loc) · 1.38 KB
/
index.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
import CurrentLocation from "./Location/CurrentLocation.js";
import MapView from "./Map/map.js";
import IpGeolocation from "./Networking/IpGeolocation.js";
window.onload = () => {
const geoLocation = new IpGeolocation();
const mapView = new MapView();
mapView.initMap();
updateLocationUI(geoLocation);
setMapToCurrentLocation(mapView);
document.querySelector(".submit-ip-btn").addEventListener("click", () => {
updateLocationUI(geoLocation,mapView);
});
};
const setMapToCurrentLocation = (mapView)=>{
const currentLocation = new CurrentLocation();
currentLocation.getCurrentLocation().then(() =>
mapView.setMapLocation(currentLocation.currentLatitude, currentLocation.currentLongitude));
}
const updateLocationUI = (geoLocation,mapView)=>{
const ip = document.querySelector(".ip-input").value;
geoLocation.getAddress(ip).then(() => {
changeLocationUI(geoLocation.locationData);
mapView.setMapLocation(geoLocation.locationData.location.lat,geoLocation.locationData.location.lng);
});
}
const changeLocationUI = (data) =>{
document.getElementById("location").innerHTML = `${data.location.country}-${data.location.region} <br> ${data.location.city}`;
document.getElementById("timezone").innerHTML = `UTC ${data.location.timezone}`;
document.getElementById("ip").innerHTML = data.ip;
document.getElementById("coordinates").innerHTML = `${data.isp}`;
}