-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoLocations.js
48 lines (40 loc) · 1.42 KB
/
GeoLocations.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
const x = document.getElementById("Logo1");
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDNnuj-ZDT-RmxNaG-1nmFCHuzmcL9eMK0",
authDomain: "geolocation-progressbar.firebaseapp.com",
databaseURL: "https://geolocation-progressbar-default-rtdb.firebaseio.com",
projectId: "geolocation-progressbar",
storageBucket: "geolocation-progressbar.appspot.com",
messagingSenderId: "148383821021",
appId: "1:148383821021:web:9870902b7a17de1aedff34",
measurementId: "G-459B7XPYCV"
};
firebase.initializeApp(firebaseConfig);
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
// x.innerHTML = "Latitude: " + latitude + "<br>Longitude: " + longitude;
saveLocation(latitude, longitude);
}
function saveLocation(latitude, longitude) {
const database = firebase.database();
const locationRef = database.ref('locations');
locationRef.push().set({
latitude: latitude,
longitude: longitude
}, function(error) {
if (error) {
console.log("Error saving location: " + error.message);
} else {
console.log("Location saved successfully.");
}
});
}