更新位置每5秒的android [英] Update location every 5sec android

查看:331
本文介绍了更新位置每5秒的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想获得每5秒和用户用户位置可以改变像10秒,15秒持续时间是30秒高达我有微调器选择此选项

Hi I want get user location for every 5sec and user can change that duration like 10sec, 15sec upto 30sec i have spinner to choose this option

这是我的要求

 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秒的位置更新正在运行的每一秒。

I can pass user selected interval to startPeriodicUpdates() method like startPeriodicUpdates(5000), startPeriodicUpdates(15000). But they location update duration working fine 15sec and more than 15sec If i give 5sec or 10 sec the location update is running for every second

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请给你的想法。

log show time interval for 23, 24, 25 please give your ideas.

推荐答案

的setInterval 方法并不精确。 <一href=\"http://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#setInterval%28long%29\"相对=nofollow>这是文件中提及。

另外,使用相同的时间间隔 setFastestInterval 的setInterval 来prevent您的应用程序接收位置更新比你的的setInterval 指定的时间间隔更快。

Also, use the same interval for setFastestInterval and setInterval to prevent your app from receiving location updates faster than the the interval you specified in setInterval.

只需添加 REQUEST.setFastestInterval(有限区间); 你的 startPeriodicUpdates

这篇关于更新位置每5秒的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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