<header>
<h2 class="title">Геолокація: Висота (altitude)</h2>
<p class="description">Цей інтерфейс показує висоту користувача в метрах, якщо вона доступна через геолокацію.</p>
</header>
<main>
<div class="result">
<button id="getLocationButton">Отримати висоту</button>
<p id="altitude">Висота: Невідома</p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
text-align: center;
}
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;
margin-top: 20px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-bottom: 10px;
border: none;
background-color: #4CAF50;
color: white;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
p {
font-size: 18px;
font-weight: bold;
}
document.getElementById("getLocationButton").addEventListener("click", function() {
// Перевірка підтримки геолокації
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
const altitude = position.coords.altitude;
// Перевіряємо, чи доступна висота
if (altitude !== null) {
document.getElementById("altitude").textContent = `Ваша висота: ${altitude} метрів`;
} else {
document.getElementById("altitude").textContent = "Висота недоступна.";
}
}, function(error) {
document.getElementById("altitude").textContent = "Помилка отримання даних геолокації.";
});
} else {
document.getElementById("altitude").textContent = "Ваш браузер не підтримує геолокацію.";
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.