및 통과에도 불구하고 :정확도가 높은 JavaScript에서 geolocation을 검색하기위한 최적의 패턴은 무엇입니까?
는{
enableHighAccuracy: true,
maximumAge: 0
}
PositionOptions로, 패턴은 내가 빠른 낮은 얻을 첫 번째 응답에이를 것으로 보인다 (location.coords.accuracy
값은 16,130만큼 높았습니다.) 두 번째 또는 세 번째 응답에서 높은 정확도 응답을 얻었습니다 (location.coords.accuracy
값은 31로 낮습니다). 지금은 GPS를 두 번 쿼리하는 setTimeout 호출 (3 초 지연)을 구현 중이며 첫 번째 응답을 무시합니다. 하지만 다른 사람이 더 나은 구현에 대한 지침을 가지고 있는지 궁금하네요. 여기에 (3 초 시간 제한과) 내 코드 (그리고 demo, 당신은 열려있는 콘솔이 필요합니다) 앱이 때문에 정확한 위치 정보를 필요로한다면 아마도 당신이 무엇인지 결정할 수,
var check = function() {
if ("geolocation" in navigator) {
console.log('looking');
navigator.geolocation.getCurrentPosition(function(location) {
console.log('Ignoring the following data:');
console.log({
lat: location.coords.latitude,
lng: location.coords.longitude,
accuracy: location.coords.accuracy});
setTimeout(function() {
navigator.geolocation.getCurrentPosition(function(location) {
console.log('On my system I am firing a Lucene Spatial search with the following data:');
console.log({
lat: location.coords.latitude,
lng: location.coords.longitude,
accuracy: location.coords.accuracy});
}, function() {
console.log('navigator error occurred on second call... weird');
}, {
enableHighAccuracy: true,
maximumAge: 0
});
}, 3000);
}, function() {
console.log('navigator error occurred on first call.');
}, {
enableHighAccuracy: true,
maximumAge: 0
});
} else {
console.log('geolocation not available');
}
}
실제 코드를 표시 하시겠습니까? 나는 그것이 얼마나 중요한지는 잘 모르겠지만 다치게 할 수는 없다. – Ian
@Ian, 코드와 JSFiddle 데모를 추가했다. –
첫 번째 결과를 무시하고 두 번째 결과를 유지하는 것보다 더 많은 것을 취해야한다고 가정하지 않는 이유는 무엇인가? N 개의 수표를 하나씩 채우고 일정을 잡아서 가장 정확하게 유지하십시오. 'getCurrentPosition' 대신 – ssube