2015-03-31 47 views
-6

in 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. 
+0

至少当errorLocation功能called..pls告诉我任何一个.. – sac 2015-03-31 06:14:01

回答

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

等待我会检查 – sac 2015-03-31 06:27:14

+0

没有发生..请给我另一种解决方案 – sac 2015-03-31 06:44:36

+0

你是什么意思没有任何反应?必须有另一个错误阻止函数从射击我猜...尝试在函数代码的不同部分使用alert('test1')alert('test2')来查看哪些正在运行,哪些不是。 – odedta 2015-03-31 06:47:47