Skip to content

Commit

Permalink
map live track enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rithasahmed12 committed Mar 8, 2024
1 parent b37a8c3 commit e45cf6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ <h1>Find The Distance Between three Places.</h1>

<div class="col-xs-offset-2 col-xs-10">
<button class="btn btn-info btn-lg " onclick="calcRoute();"><i class="fas fa-map-signs"></i></button>
<button onclick="stopLiveTracking()">stop</button>
</div>
</div>
<div class="container-fluid">
Expand Down
11 changes: 11 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function startLiveTracking() {

// Function to track user's position
function trackUser(position) {
console.log('position:',position);
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;

Expand All @@ -193,6 +194,7 @@ function trackUser(position) {
if (distanceToDestination < ARRIVAL_THRESHOLD) {
// User has reached the destination, stop tracking
stopLiveTracking();
alert('reached');
console.log("You have reached your destination!");
}
}
Expand All @@ -202,6 +204,15 @@ function stopLiveTracking() {
if (watchId) {
navigator.geolocation.clearWatch(watchId);
watchId = undefined;
}

// Clear the directions displayed on the map
directionsDisplay.setDirections({ routes: [] });

// Remove the destination marker from the map
if (marker) {
marker.setMap(null);
marker = undefined; // Reset marker variable
}
}

Expand Down

0 comments on commit e45cf6e

Please sign in to comment.