navigator.geolocation.getCurrentPosition()首页没有执行这个方法 ,再次刷新 才可执行

问题:IOS系统首次进入页面,有进if (navigator.geolocation){}添加,但没有执行 navigator.geolocation.getCurrentPosition(this.showPosition.bind(this), this.showError.bind(this), options);
没进入showPosition(),也没有进入showError()事件
安卓机正常,不会出现这个问题
代码:

  if(navigator.geolocation){
    console.log(navigator.geolocation);
  alert(1);
  const options = {
    enableHightAcuracy: false, // 指示浏览器获取高精度的位置,默认为false
    timeout: 6000, // 指定获取地理位置的超时时间,默认不限时,单位为毫秒
    maximunAge: 30000 // 最长有效期,在重复获取地理位置时,此参数指定多久再次获取位置。
  };
navigator.geolocation.getCurrentPosition(this.showPosition.bind(this), this.showError.bind(this), options);
  
} else {
  console.log('该浏览器不支持获取地理位置');
   alert('该浏览器不支持获取地理位置');
  this.cityName = sessionStorage.getItem(COMMON.CITY_NAME);
  this.goPage();
}
阅读 3.5k
1 个回答

加个window.onload

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题