简体   繁体   English

如果车辆没有移动,每5分钟后Android位置更新

[英]Android Location Update After Every 5min If Vehicle Not Moving

I have a situation like the following: 我有以下情况:

If car is stationary(not moving) than i want to call location update api after every 5min. 如果汽车静止(不动),我想在每5分钟后调用位置更新api。 If car is moving than i want to call location update api after every 2min. 如果汽车正在移动,我想每隔2分钟后调用位置更新api。

or 要么

If car keep moving 2000 meters distance than need to call location update api after every 5min.Actually how to check that location is same or not? 如果汽车每隔5分钟移动2000米的距离比需要呼叫位置更新api。实际上如何检查该位置是否相同?

You can receive Information about location changes with the Location Update Callback . 您可以使用Location Update Callback接收有关位置更改的信息。 Read more about it in the android developer docs . android开发人员文档中阅读更多相关信息。 Here is a basic example on how you can detect if the location changed: 以下是如何检测位置是否发生变化的基本示例:

public class MainActivity extends ActionBarActivity implements LocationListener {
    private Location mLastKnownLocation;
    ...
    @Override
    public void onLocationChanged(Location location) {          
            //location changed
            mLastKnownLocation = location
        }           
    }
}

Basically you just receive information about the current location if the location changed . 基本上,如果位置发生变化,您只会收到有关当前位置的信息。

So in your case where you want to know every 5 min / 2 min if the location changed implement a timer, loop, etc. to check every 5 min / 2 min if you received a locationChangedEvent and the location changed or not 所以在你的情况下你想要知道每5分钟/ 2分钟如果位置发生变化,实施定时器,循环等,如果你收到了locationChangedEvent并且位置发生了变化,则每5分钟/ 2分钟检查一次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM