这个功能如何运作

时间:2015-03-31 06:05:19

标签: javascript jquery

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.

1 个答案:

答案 0 :(得分:0)

使用此代码段并检查开发人员工具控制台以查看错误:

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