When we have a requirement where we want to track the latest location of a user when he is in a specific area, then we write separate code. The code in the HTML that determines when to prompt the user to share their location 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 first load. It will check whether the user is here for the first time; if so, the navigator gets the current location. After that, based on the coordinates in the box, we observe the position. If the user is at a certain location, observe the location.
The above is the detailed content of How does mobile Safari determine when to prompt the user to share location in HTML?. For more information, please follow other related articles on the PHP Chinese website!