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`);
|
||||
15
4-Geolocation/index.html
Normal file
15
4-Geolocation/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="app.js" defer></script>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user