[Link]('track-btn').
addEventListener('click', function() {
if ([Link]) {
[Link](showPosition, showError);
} else {
alert("Geolocation is not supported by this browser.");
}
});
function showPosition(position) {
const lat = [Link];
const lon = [Link];
[Link]('coords').innerHTML = `Latitude: ${lat}<br>Longitude: $
{lon}`;
// Initialize map
const map = [Link]('map').setView([lat, lon], 13);
[Link]('[Link] {
attribution: '© <a
href="[Link] contributors'
}).addTo(map);
// Add marker
[Link]([lat, lon]).addTo(map)
.bindPopup('You are here!')
.openPopup();
}
function showError(error) {
switch([Link]) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case [Link]:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}