【发布时间】:2019-02-17 17:50:09
【问题描述】:
以下方法用于开始和停止位置跟踪,使用我的应用程序几乎每分钟连续轮询位置。我只想在坐标发生变化时捕获该位置。我想知道有什么方法可以在发生变化时进行比较和检索位置。 我试图手动比较使请求变慢的坐标。请指教。
public void stopTracking() {
if (time != null) {
time.cancel();
}
time = null;
LocationManager.getLocationManager().setLocationListener(null);
}
public void startTracking() {
if (time != null) {
stopTracking();
}
if (Preferences.get("LocationTracking", true)) {
long delay = Server.instance.getLoctionPollingIntervalMillis();
LocationManager.getLocationManager().setLocationListener(this,
new LocationRequest(LocationRequest.PRIORITY_LOW_ACCUARCY, delay));
time = new Timer();
time.schedule(new TimerTask() {
@Override
public void run() {
if (lastLocation != null) {
double lat = (double) lastLocation.getLatitude();
double lot = (double) lastLocation.getLongitude();
Server.instance.updateLocationInServer(lat, lot, System.currentTimeMillis(), true);
}
}
}, 30000, delay);
}
}
【问题讨论】:
标签: codenameone