How does mobile safari determine when to prompt user to share location?

╄→гoц情女王★ 提交于 2019-12-23 20:56:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!