获取当前纬度长的android纬度、android

2023-09-07 13:23:52 作者:Taste丿汏少爷丶

我想获得按钮preSS位置的对象。我知道LocationListener的回调,但它们只在特定的时间或距离之后执行。我想获得位置瞬间。有没有做任何这样的方法。

I want to get the Location object on Button press. I know the LocationListener callbacks, however they execute only after a particular time or distance. I want to get Location instantaneously. Are there any methods to do so.

推荐答案

您,欢迎来电 getLastKnownLocation()的LocationManager 来检索最后已知位置为您要求的位置提供。但是:

You are welcome to call getLastKnownLocation() on LocationManager to retrieve the last known location for your requested location provider. However:

该位置可能是旧该位置可能是 that location may be old that location may be null

因此​​,你的code将需要能够应对这两个方案中的

Hence, your code will need to be able to cope with both of those scenarios.