Skip to content

Commit

Permalink
Display how long we've been waiting for
Browse files Browse the repository at this point in the history
  • Loading branch information
nomis committed Jun 11, 2023
1 parent 90c4004 commit 49d2b9e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ <h1>Current Location</h1>
<p>
<span id="status">Loading</span><br>
<span id="attempt" style="visibility: hidden">
Last attempt: <span id="when_attempt">?</span>s ago<br>
<span id="when_attempt">Last attempt: ?s ago</span><br>
</span>
<span id="details" style="visibility: hidden">
<br>
Latitude: <span id="geo_lat">?</span><br>
Longitude: <span id="geo_lon">?</span><br>
Accuracy: ±<span id="geo_acc">?</span>m<br>
<br>
Latitude: <span id="geo_lat">?</span><br>
Longitude: <span id="geo_lon">?</span><br>
Accuracy: ±<span id="geo_acc">?</span>m<br>
</span>
<span id="updated" style="visibility: hidden">
<br>
Last updated: <span id="when_updated">?</span>s ago<br>
<br>
Last updated: <span id="when_updated">?</span>s ago<br>
</span>
</p>
<nav>
Expand Down Expand Up @@ -141,6 +141,7 @@ <h2>Enter <label for="location">Location</label></h2>
var geo_retry = undefined;
var geo_time_u = undefined;
var geo_time_a = undefined;
var geo_time_w = undefined;
var geo_timer = undefined;

function goto_location() {
Expand Down Expand Up @@ -232,7 +233,9 @@ <h2>Enter <label for="location">Location</label></h2>
retry.style = "";

if (navigator.geolocation) {
document.getElementById("status").innerText = "⏳ Waiting for location";
document.getElementById("status").innerText = "⏳ Requesting your location";
geo_time_w = Date.now();
geo_relative_timer();

geo_handler = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
} else {
Expand All @@ -258,6 +261,7 @@ <h2>Enter <label for="location">Location</label></h2>
}

retry.style = "";
geo_time_w = undefined;
geo_relative_timer();
}

Expand All @@ -272,15 +276,18 @@ <h2>Enter <label for="location">Location</label></h2>

function geo_relative_time() {
if (geo_time_u != undefined) {
document.getElementById("updated").style = "";
document.getElementById("when_updated").innerText = `${Math.round((Date.now() - geo_time_u) / 1000)}`;
document.getElementById("updated").style = "";
} else {
document.getElementById("updated").style = "visibility: hidden";
}

if (geo_time_a != undefined) {
if (geo_time_w != undefined) {
document.getElementById("when_attempt").innerText = `Waiting for: ${Math.round((Date.now() - geo_time_w) / 1000)}s`;
document.getElementById("attempt").style = "";
} else if (geo_time_a != undefined) {
document.getElementById("when_attempt").innerText = `Last attempt: ${Math.round((Date.now() - geo_time_a) / 1000)}s ago`;
document.getElementById("attempt").style = "";
document.getElementById("when_attempt").innerText = `${Math.round((Date.now() - geo_time_a) / 1000)}`;
} else {
document.getElementById("attempt").style = "visibility: hidden";
}
Expand Down Expand Up @@ -346,6 +353,7 @@ <h2>Enter <label for="location">Location</label></h2>
}

document.getElementById("attempt").style = "visibility: hidden";
geo_time_w = undefined;
}
}

Expand Down

0 comments on commit 49d2b9e

Please sign in to comment.