【发布时间】:2014-06-18 13:20:02
【问题描述】:
您好,我希望每 5 秒获取一次用户位置,用户可以更改该持续时间,例如 10 秒、15 秒到 30 秒,我有微调器可以选择此选项
这是我的要求
private static final LocationRequest REQUEST = LocationRequest.create()
.setInterval(5000) // 5 seconds
.setFastestInterval(16) // 16ms = 60fps
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
这是启动我的开始更新
private void startPeriodicUpdates(int intervel) {
stopPeriodicUpdates();
REQUEST.setInterval(intervel);
mLocationClient.requestLocationUpdates(REQUEST, this);
// mConnectionState.setText(R.string.location_requested);
}
我可以将用户选择的时间间隔传递给 startPeriodicUpdates() 方法,例如 startPeriodicUpdates(5000)、startPeriodicUpdates(15000)。但他们的位置更新持续时间工作正常 15 秒和超过 15 秒 如果我给 5 秒或 10 秒,则位置更新每秒运行一次
06-18 18:46:23.638: I/Location(2860): Location Changed Location[fused 65.966697,-18.533300 acc=4 et=+1h0m13s881ms alt=15.044444]
06-18 18:46:24.642: I/Location(2860): Location Changed Location[fused 65.966697,-18.533300 acc=4 et=+1h0m14s883ms alt=15.044444]
06-18 18:46:25.642: I/Location(2860): Location Changed Location[fused 65.966697,-18.533300 acc=4 et=+1h0m15s883ms alt=15.044444]
日志显示时间间隔为23、24、25请给出你的想法。
【问题讨论】:
-
你在后台使用服务吗?
-
因为你需要每次注册 locationlistner 但它 0 到 30-40 不会更新位置它需要一点时间
-
@DevilAbhi 仅在活动中。
-
@PankajAndroid 是的,我每次都注册。它更新。我的问题是 5 秒和 10 秒的间隔更新持续时间是错误的,它每秒更新一次,但超过 15 秒工作正常。我该怎么办?
标签: android google-maps android-location