first commit with existing project files
This commit is contained in:
33
4-Geolocation/app.js
Normal file
33
4-Geolocation/app.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const options = {
|
||||
enableHighAccuracy: true,
|
||||
timeout: 5000,
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
function success(pos) {
|
||||
localStorage.setItem('position',
|
||||
JSON.stringify(pos.coords)
|
||||
);
|
||||
}
|
||||
|
||||
function error(err) {
|
||||
console.warn(`ERROR(${err.code}): ${err.message}`);
|
||||
}
|
||||
|
||||
navigator.geolocation.getCurrentPosition(success, error, options);
|
||||
|
||||
const getCoordinates = () => {
|
||||
const parsed = JSON.parse(localStorage.getItem('position'));
|
||||
return {
|
||||
latitude: parsed.latitude,
|
||||
longitude: parsed.longitude,
|
||||
accuracy: parsed.accuracy,
|
||||
altitude: parsed.altitude,
|
||||
altitudeAccuracy: parsed.altitudeAccuracy,
|
||||
heading: parsed.heading,
|
||||
speed: parsed.speed
|
||||
};
|
||||
}
|
||||
|
||||
console.log(`Latitude: ${getCoordinates().latitude}, Longitude: ${getCoordinates().longitude}
|
||||
Accuracy: ${getCoordinates().accuracy.toFixed()} meters`);
|
||||
Reference in New Issue
Block a user