安卓locationManager requestLocationUpdates [英] android locationManager requestLocationUpdates

查看:164
本文介绍了安卓locationManager requestLocationUpdates的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法请求位置更新,从locationManager在特定intervan,而忽略minDistance依旧?我试过

Is there a way to request location updates from a locationManager at specific intervan and to ignore minDistance? 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?

推荐答案

您可以使用此模式。创建新的Runnable它都会被调用一次,当你需要它

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);
}

这篇关于安卓locationManager requestLocationUpdates的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆