Android - Reliably getting the current location

后端 未结 2 520
既然无缘
既然无缘 2020-12-08 09:04

My app checks at a specific time whether a user is at a given location. I use the alarm manager to start a service that makes this call:

locationManager.requ         


        
2条回答
  •  一个人的身影
    2020-12-08 09:29

    If the user's location is already stable, then getLastKnownLocation will return the current location. I'd call getLastKnownLocation first, look at the timestamp (compare Location.getElapsedRealTimeNanos() with SystemClock.elapsedRealTimeNanos()) then register a listener if the fix is too old.

提交回复
热议问题