# How does mobile safari determine when to prompt the user to share location in HTML?

When we have a requirement in which we want to track the latest locations for a user only when they are in a certain area, then we write separate code for it. The code to determine when to prompt the user to share location in HTML is as follows -

if (frstTime) { //First time
navigator.getCurrentPosition(function (coordinates) {
if (coordsAreInTheBox) {
storeCoordsForUser();
navigator.watchPosition();
}
});
}

else if (userInlocat) {
navigator.watchPosition();
}

It works as expected on the first load. It will check for whether the user came for the first time; if yes, then the navigator gets the current position. After that, according to coordinates in the box, we watch positions. If the user is in location then watch position.

Samual Sam

Learning faster. Every day.