<header>
<h2 class="title">Geolocation -> accuracy</h2>
<p class="description">Виводить точність визначення місцезнаходження користувача у метрах.</p>
</header>
<main>
<div class="result">
<button id="getLocationBtn">Отримати точність геолокації</button>
<p id="accuracyOutput">Точність: не визначено</p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
p {
font-size: 18px;
color: #333;
}
document.getElementById('getLocationBtn').addEventListener('click', function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
// Отримуємо точність геолокації
const accuracy = position.coords.accuracy;
// Виводимо точність на екран
document.getElementById('accuracyOutput').textContent = `Точність: ${accuracy} метрів`;
}, function(error) {
document.getElementById('accuracyOutput').textContent = 'Помилка: Не вдалося отримати геолокацію';
});
} else {
document.getElementById('accuracyOutput').textContent = 'Геолокація не підтримується в цьому браузері';
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.