user1386101
user1386101

Reputation: 1944

Needed assistance with getting the users location if there is a change in the users position using HTML5 and JS

I need some help in tracking the user continuously. According to the research I did, the watchPosition function will return the new position if there is a change in user's location. Is that correct? And also where should this snippet be placed, right after the getCurrentPosition function? If not so, do you have any solutions or suggestions how I can achieve continuous tracking.

navigator.geolocation.watchPosition(
function(position) {
    calculateDistance(position.coords.latitude, position.coords.longitude);
}, function(err){ 
    console.log(err);
}, {enableHighAccuracy:true, maximumAge:30000, timeout:27000});

Upvotes: 0

Views: 52

Answers (1)

Ian Devlin
Ian Devlin

Reputation: 18870

Yes you are correct and you don't need to call getCurrentPosition() at all as watchPosition() does the same thing, only continously.

So call it instead of where you are currently calling getCurrentPosition().

Upvotes: 1

Related Questions