移动版 Safari 如何确定何时在 HTML 中提示用户分享位置?

htmlweb developmentfront end technology更新于 2024/8/23 10:20:17

当我们有需求,需要仅在用户位于特定区域时追踪其最新位置时,我们会为此编写单独的代码。用于确定何时在 HTML 中提示用户分享位置的代码如下 -

if (frstTime) { //第一次    
  navigator.getCurrentPosition(function (coordinates) {      
      if (coordsAreInTheBox) {          
        storeCoordsForUser();          
        navigator.watchPosition();      
      }    
   });
}  

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

首次加载时,它会按预期工作。它会检查用户是否是第一次访问;如果是,则导航器获取当前位置。之后,我们会根据框中的坐标监视位置。如果用户位于该位置,则监视位置。


相关文章


有用资源