Android GPS如何跳过距离?
我正在开发一个支持 GPS 的应用程序,我需要每 N 米记录一个点。但是,我看不到如何在 LocationListener 或任何其他方法/类中使用 onLocationChanged() 方法。 onLocationChanged() 方法每秒给出一个点,我需要存储每个 N 米的点。
我相信这有一个简单的解决方案,但由于我是 Android 初学者,找不到它。
任何帮助将不胜感激。
I am working on a GPS-enabled application and I need to record a point each N meters. However, I can't see how I can use onLocationChanged() method in the LocationListener or any other method/class. The onLocationChanged() method gives a point each second, and I need to store each N-meter point.
I believe that this has a simple solution, but since I am beginner in Android, cant find it.
Any help will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
requestLocationUpdates
有一个 minDistance 参数,即如果我没记错的话,可以做你想要的。不过我还没有在真机上进行过测试,所以我不知道它的准确性。
requestLocationUpdates
has a minDistance parameter, thatif I recall correctly does what you want. I haven't been able to test this on a real phone though, so I don't know how accurate it is.
在
onLocationChanged
中,将您获取的位置与您上次存储的位置进行比较。如果小于n
米,则丢弃它。如果没有,请将其存储。冲洗。重复。编辑:等等,更简单 -
requestLocationUpdates
没有minDistance
参数吗?请参阅此处: http://developer.android.com/reference/android/位置/LocationManager.html#requestLocationUpdatesIn
onLocationChanged
, compare the location you get with the last one you stored. If it's less thann
meters, discard it. If not, store it. Rinse. Repeat.EDIT: Wait, even easier - doesn't
requestLocationUpdates
have aminDistance
parameter? See here: http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates它工作得很好
myManager = ((LocationManager) ApplicationController.getAppContext().getSystemService( Context.LOCATION_SERVICE ));
myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1 * 1000, 0.00001f, this);
mintime =1000ms 总是在调用....
it is working perfectly
myManager = ((LocationManager) ApplicationController.getAppContext().getSystemService( Context.LOCATION_SERVICE ));
myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1 * 1000, 0.00001f, this);
mintime =1000ms always it is calling ....