开发者

android locationManager requestLocationUpdates

开发者 https://www.devze.com 2023-03-04 15:56 出处:网络
Is there a way to request location updates from a locationManager at specific intervan and to ignore minDistanc开发者_高级运维e? I\'ve tried

Is there a way to request location updates from a locationManager at specific intervan and to ignore minDistanc开发者_高级运维e? I've tried

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3600 * 1000, 1, this)

But in logs appears sometimes that location is updated in a few minutes, sometimes in a half of hour... Can this be done to update location at a fixed interval and to ignore distance?


You can use this schema. Create new Runnable which will be called every time, when you want it

private final Handler _handler = new Handler();
private static int DATA_INTERVAL =  60 * 1000;

private final Runnable getData = new Runnable()
{
    @Override
    public void run()
    {
        getDataFrame();
    }
};
private void getDataFrame() 
{
    requestGPS();
    Timer time = new Timer();
    time.schedule(new TimerTask() {
            @Override
            public void run() {
                _locationManager.removeUpdates(_connector);
                this.cancel();
            }
        }, 5000, 5000);
    _handler.postDelayed(getData, DATA_INTERVAL);
}
private void requestGPS() 
{
    _locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER,
                0,
                0,
                _connector);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消