鍍金池/ 問答/HTML5  HTML/ navigator.geolocation.getCurrentPosition

navigator.geolocation.getCurrentPosition()首頁沒有執(zhí)行這個方法 ,再次刷新 才可執(zhí)行

問題:IOS系統(tǒng)首次進入頁面,有進if (navigator.geolocation){}添加,但沒有執(zhí)行 navigator.geolocation.getCurrentPosition(this.showPosition.bind(this), this.showError.bind(this), options);
沒進入showPosition(),也沒有進入showError()事件
安卓機正常,不會出現(xiàn)這個問題
代碼:

  if(navigator.geolocation){
    console.log(navigator.geolocation);
  alert(1);
  const options = {
    enableHightAcuracy: false, // 指示瀏覽器獲取高精度的位置,默認為false
    timeout: 6000, // 指定獲取地理位置的超時時間,默認不限時,單位為毫秒
    maximunAge: 30000 // 最長有效期,在重復獲取地理位置時,此參數(shù)指定多久再次獲取位置。
  };
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();
}
回答
編輯回答
挽歌

加個window.onload

2018年4月1日 22:34