鍍金池/ 問(wèn)答/HTML5  網(wǎng)絡(luò)安全  HTML/ 獲取地理位置:navigator.geolocation.getCurrentP

獲取地理位置:navigator.geolocation.getCurrentPosition 無(wú)效

MDN的例子,本地運(yùn)行沒(méi)有打印地理位置,也沒(méi)有報(bào)錯(cuò),為何?求指導(dǎo)
剛開(kāi)始PC端一直返回超時(shí),可能是PC端不支持,用手機(jī)打開(kāi)后又提示:error.code 1 PERMISSION_DENIED

手機(jī)谷歌瀏覽器報(bào)錯(cuò):err.code 1,不允許獲取地理位置,如何解決?
哪里可以重新打開(kāi)允許或者js如何修改是否允許?

    var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };
    ?
    function success(pos) {
      var crd = pos.coords;
    ?
      console.log('Your current position is:');
      console.log('Latitude : ' + crd.latitude);
      console.log('Longitude: ' + crd.longitude);
      console.log('More or less ' + crd.accuracy + ' meters.');
    };
    ?
    function error(err) {
      console.warn('ERROR(' + err.code + '): ' + err.message);
};
?
navigator.geolocation.getCurrentPosition(success, error, options);

clipboard.png

回答
編輯回答
熊出沒(méi)

getCurrentPosition是異步的,調(diào)用后并不會(huì)立即返回結(jié)果。

你的截圖里面已經(jīng)打印錯(cuò)誤信息了,就是ERROR(3): Timeout expired,說(shuō)明請(qǐng)求超時(shí)了。

2018年2月21日 15:49