Skip to content

Commit

Permalink
feat(distance): add walking time (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorWinberg authored Jun 30, 2023
1 parent b23e3e3 commit 5bed7dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/src/components/QRSpot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<div class="qrspot-info__distance">
<i class="fas fa-route"></i>
{{ distanceToMarker(userCoords, qrSpot) }}
-
<i class="fas fa-clock"></i>
{{ walkingTimeToMarker(userCoords, qrSpot) }}
</div>
<!-- <div class="qrspot-info__rating">
<i class="far fa-star"></i>
Expand Down Expand Up @@ -45,7 +48,7 @@ import { mapState, mapMutations } from "vuex";
import { QR_SPOT_MODE, QR_SPOT_PANEL } from "@/constants";
import QRSpotView from "./QRSpotView";
import QRSpotUpdate from "./QRSpotUpdate";
import { distance } from "@/utils";
import { distance, calculateWalkingTime } from "@/utils";
export default Vue.extend({
name: "QRSpot",
Expand All @@ -72,7 +75,13 @@ export default Vue.extend({
distanceToMarker(pos1, pos2) {
if (!pos1 || !pos2) return "N/A";
const d = distance(pos1, pos2);
return d < 1000 ? d.toFixed(1) + " m" : (d / 1000).toFixed(1) + " km";
return d < 1000 ? d.toFixed(0) + " m" : (d / 1000).toFixed(1) + " km";
},
walkingTimeToMarker(pos1, pos2) {
if (!pos1 || !pos2) return "N/A";
const d = distance(pos1, pos2);
const min = calculateWalkingTime(d);
return min < 60 ? min.toFixed(0) + " min" : (min / 60).toFixed(1) + " hr";
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,9 @@ export function distance({ lat: lat1, lng: lng1 }, { lat: lat2, lng: lng2 }) {
const d = R * c;
return d;
}

export function calculateWalkingTime(distanceInMeters: number) {
const walkingSpeed = 1.2;
const walkingTimeInSeconds = distanceInMeters / walkingSpeed;
return Math.ceil(walkingTimeInSeconds / 60);
}

0 comments on commit 5bed7dd

Please sign in to comment.