问题
I have a mobile web app where I want to track the latest location for a user, but only if they are in a certain area. But, having a little trouble with excessive prompts on the iPhone
There's some location initialization code along the lines of:
if (firstTime) {
navigator.getCurrentPosition(function (coords) {
if (coordsAreInTheBox) {
storeCoordsForUser();
navigator.watchPosition();
}
});
} else if (userInTheBox) {
navigator.watchPosition();
}
This works as expected on the first load, there is only a ".. would like to use your location" prompt on the initial getCurrentPosition call, not on the watchPosition.
But, on some (not all) subsequent loads, when the watchPosition is called, it is prompting again to share location. What would cause mobile safari to prompt again for a site that the user has already shared the location for?
来源:https://stackoverflow.com/questions/8938080/how-does-mobile-safari-determine-when-to-prompt-user-to-share-location