【问题标题】:how this function works这个函数是如何工作的
【发布时间】:2015-03-31 06:05:19
【问题描述】:

在 javaScript 中:navigator.geolocation.getCurrentPosition(onSuccessLocation, onErrorLocation);

In the above code Success Location working fine when i click share location button popup (would you like to share your location) in browser. but i want  Error Location. it will not working when i clicked Not Now in browser.

【问题讨论】:

  • 至少在调用 errorLocation 函数时..请告诉我任何人..

标签: javascript jquery


【解决方案1】:

使用此 sn-p 并检查您的开发人员工具控制台以查看错误:

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);

【讨论】:

  • 什么都没有发生是什么意思?我猜肯定有另一个错误阻止函数触发...尝试在函数代码的不同部分使用 alert('test1') alert('test2') 来查看哪些正在运行,哪些没有运行。
  • alert("test1") 很好.. 当单击浏览器中的共享位置弹出窗口时。但是当我在浏览器中单击 not now popup 时,没有任何反应意味着警报(“tast2)没有出现。我将 test2 放入错误函数中 ..
  • 你去,你必须找出为什么 alert('test2') 没有触发,尝试添加更多的警报。此外,我强烈建议您使用validator.w3.org 验证您的 HTML 以确保您没有任何错误。
猜你喜欢
  • 2018-07-17
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-29
相关资源
最近更新 更多