安卓:使用requestSingleUpdate或更换 [英] Android: using requestSingleUpdate or replace it

查看:1195
本文介绍了安卓:使用requestSingleUpdate或更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序,它必须得到经度和纬度。在我的情况 requestLocationUpdates(字符串提供商,长期minTime,浮minDistance依旧,LocationListener的听众)不在选项。为什么?因为我必须把位置只是当用户做到这一点,需要的东西位置(比方说他打按钮)。我需要准确的时间,当按钮被击中的位置。在 requestLocationUpdates ,我们可以设置minTime,如果我设置这种假设在30000的按钮命中时间的位置不会不如我想要的。同样的道理minDistance依旧还不如我想要的。如果我understant功能 requestLocationUpdates 正确的,当minTime和minDistance依旧被设置为0,位置更新所有的时间。请纠正我,如果我错了。应用程序是为我在工作的公司,该应用程序将通过白天和夜间使用。因此,如果应用程序将检查位置更新的时候,电池会经常空。 THST就是为什么我只是在需要的时间地点,该按钮被击中。我发现<一个href=\"http://developer.android.com/reference/android/location/LocationManager.html#requestSingleUpdate%28java.lang.String,%20android.location.LocationListener,%20android.os.Looper%29\"相对=nofollow> requestSingleUpdate 功能。但我不能在Eclipse中使用它=(像它不存在。结果
有一些其他的方式来做到这一点还是我失去了一些东西?

i'm working on app, which must get latitude and longitude. in my case requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener) is not in option. why? because i must get location just when user do something that location is needed (let's say he hits button). and i need location exactly on the time, when button is hit. in requestLocationUpdates, we can set minTime-if i set this let's say on 30000 the location at the "button hit time" won't be as good as i want. of the same reason minDistance is also not as good as i want. if i understant function requestLocationUpdates correct-when minTime and minDistance are set to 0, location is updating all the time. please correct me if i'm wrong. app is for company that i'm working at and that app will be used through the day and night. so if app will check for location updates all the time, battery would be often empty. thst's why i need location just at the time, that button is hit. i found requestSingleUpdate function. but i can't use it in eclipse =( like it doesn't exists.
is there some other way to do this or am i missing something?

推荐答案

您可以使用<一个href=\"http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation%28java.lang.String%29\"相对=nofollow> getLastKnownLocation 方法,但也可以是外的日期。 requestLocationUpdates是异步的,因为GPS需要热身中找到新的位置。
requestSingleUpdate方法是自API级9可用的,但你可以实现它使用requestLocationUpdates和禁用先回调后LocationListener的更新。

You can use getLastKnownLocation method, but it can be out-of-date. requestLocationUpdates is asynchronous because gps needs to "warm-up" to find new location. requestSingleUpdate method is available since api level 9, but you can implements it's using requestLocationUpdates and disabling updates after first callback to LocationListener.

这篇关于安卓:使用requestSingleUpdate或更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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