Skip to content

Commit

Permalink
Update hamm_mn13.html
Browse files Browse the repository at this point in the history
  • Loading branch information
mreicher authored Jun 1, 2023
1 parent 437de9b commit 3e1fd2c
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions tour/hamm/hamm_mn13.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,54 +451,55 @@ <h3>Streets of St. Paul</h3>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>

<script>
function getDistanceFromLatLonInFeet(lat1, lon1, lat2, lon2) {
const R = 20908800; // Radius of the earth in feet
const dLat = deg2rad(lat2 - lat1); // deg2rad below
const dLon = deg2rad(lon2 - lon1);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // Distance in feet
return d;
}

function deg2rad(deg) {
return deg * (Math.PI / 180);
}
function getDistanceFromLatLonInFeet(lat1, lon1, lat2, lon2) {
const R = 20908800; // Radius of the earth in feet
const dLat = deg2rad(lat2 - lat1); // deg2rad below
const dLon = deg2rad(lon2 - lon1);
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // Distance in feet
return d;
}

function updateDistance(latitude, longitude) {
const centerLat = 44.962440539863806; // Center latitude
const centerLong = -93.07089205405951; // Center longitude
const distance = getDistanceFromLatLonInFeet(latitude, longitude, centerLat, centerLong);
document.getElementById("latitude").textContent = latitude.toFixed(6);
document.getElementById("longitude").textContent = longitude.toFixed(6);
document.getElementById("distance").textContent = distance.toFixed(2) + " ft";
if (distance >= 18) {
setTimeout(() => {
window.location.href = "/hamm_map.html";
}, 3000); // Redirect after 3 seconds
}
function deg2rad(deg) {
return deg * (Math.PI / 180);
}

function updateDistance(latitude, longitude) {
const centerLat = 44.962440539863806; // Center latitude
const centerLong = -93.07089205405951; // Center longitude
const distance = getDistanceFromLatLonInFeet(latitude, longitude, centerLat, centerLong);

if (distance >= 18) {
setTimeout(() => {
window.location.href = "/hamm_map.html";
}, 3000); // Redirect after 3 seconds
}
}

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(
(position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
updateDistance(latitude, longitude);
},
() => {
alert("Unable to retrieve location."); // Error handling
}
);
} else {
alert("Geolocation is not supported by this browser."); // Error handling
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(
(position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
updateDistance(latitude, longitude);
},
() => {
alert("Unable to retrieve location."); // Error handling
}
);
} else {
alert("Geolocation is not supported by this browser."); // Error handling
}
}

getLocation();


getLocation();
</script>
</body>
</html>

0 comments on commit 3e1fd2c

Please sign in to comment.