私は JavaScript Geolocation API (主に iOS 6 および Android Jellybean デバイス) で遊んでいます。
{
enableHighAccuracy: true,
maximumAge: 0
}
PositionOptions として、パターンは、最初の応答では高速で低精度の応答 (location.coords.accuracy
値は 16,130 と同じくらい高い) を取得し、2 番目または 3 番目の応答では高精度の応答 (location.coords.accuracy
値は31)。現在、setTimeout 呼び出し (3 秒の遅延) を実装して GPS を 2 回クエリしていますが、最初の応答は無視しています。しかし、他の誰かがより良い実装に関する指針を持っているかどうか疑問に思っています。これが私のコードです(3秒のタイムアウトあり)(およびデモ、コンソールを開く必要があります)
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');
}
}