0

GPS 位置情報を非常に高速に更新すると問題が発生します。100 ミリ秒ごとに位置情報を更新する必要があります。私のソリューションでは、GPSの位置が毎秒更新され、より速くは更新されないことがわかります:( setIntervalで試しました:

function localize(){


    if(navigator.geolocation)
    {


        navigator.geolocation.getCurrentPosition(function(position){

                                                 var element = document.getElementById('geolocation');
                                                 element.innerHTML = 'Latitude: '          + position.coords.latitude         + '<br />' +
                                                 'Longitude: '         + position.coords.longitude        + '<br />' +
                                                 'Altitude: '          + position.coords.altitude         + '<br />' +
                                                 'Accuracy: '          + position.coords.accuracy         + '<br />' +
                                                 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
                                                 'Heading: '           + position.coords.heading          + '<br />' +
                                                 'Speed: '             + position.coords.speed            + '<br />' +
                                                 'Timestamp: '         + position.timestamp               + '<br />';
                                                 },function(error){
                                                 alert('code: '    + error.code    + '\n' +
                                                       'message: ' + error.message + '\n');
                                                 }, { maximumAge:100, timeout:100, enableHighAccuracy:true  });

    }else{
        handleNoGeolocation(false);
    }

}
localize();
setInterval(localize, 100);
}

setTimeout を使用:

localize();
function localize(){


    if(navigator.geolocation)
    {


        navigator.geolocation.getCurrentPosition(function(position){

                                                 var element = document.getElementById('geolocation');
                                                 element.innerHTML = 'Latitude: '          + position.coords.latitude         + '<br />' +
                                                 'Longitude: '         + position.coords.longitude        + '<br />' +
                                                 'Altitude: '          + position.coords.altitude         + '<br />' +
                                                 'Accuracy: '          + position.coords.accuracy         + '<br />' +
                                                 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
                                                 'Heading: '           + position.coords.heading          + '<br />' +
                                                 'Speed: '             + position.coords.speed            + '<br />' +
                                                 'Timestamp: '         + position.timestamp               + '<br />';
                                                 },function(error){
                                                 alert('code: '    + error.code    + '\n' +
                                                       'message: ' + error.message + '\n');
                                                 }, { maximumAge:100, timeout:100, enableHighAccuracy:true  });
        setTimeout(localize, 100);
    }else{
        handleNoGeolocation(false);
    }

}

setInterval(localize, 100);
}

または whatchPosition:

localize();
function localize(){


    if(navigator.geolocation)
    {


        navigator.geolocation.watchPosition(function(position){

                                                 var element = document.getElementById('geolocation');
                                                 element.innerHTML = 'Latitude: '          + position.coords.latitude         + '<br />' +
                                                 'Longitude: '         + position.coords.longitude        + '<br />' +
                                                 'Altitude: '          + position.coords.altitude         + '<br />' +
                                                 'Accuracy: '          + position.coords.accuracy         + '<br />' +
                                                 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
                                                 'Heading: '           + position.coords.heading          + '<br />' +
                                                 'Speed: '             + position.coords.speed            + '<br />' +
                                                 'Timestamp: '         + position.timestamp               + '<br />';
                                                 },function(error){
                                                 alert('code: '    + error.code    + '\n' +
                                                       'message: ' + error.message + '\n');
                                                 }, { maximumAge:100, timeout:100, enableHighAccuracy:true  });
        setTimeout(localize, 100); //with or without
    }else{
        handleNoGeolocation(false);
    }

}


}

maximumAge および timeout オプションの有無にかかわらず試しました。私の端末はiPhone5です。

4

2 に答える 2

0

消費者向け携帯電話の GPS デバイスは、1 秒に 1 回しか更新されません。何をしても、100ミリ秒の間隔は得られません。

そのため、アルゴリズム (補間) を変更して 1 秒で動作するようにします。

于 2013-09-30T17:31:49.023 に答える