How do i get my last known location in android?

前端 未结 3 1395
一个人的身影
一个人的身影 2020-12-12 05:24

I am using google play services to get my last location. the project is working fine without force closing, however, it never gets any location. i assume it doesn\'t require

3条回答
  •  孤城傲影
    2020-12-12 05:38

    GetLastLocation is called by the FusedLocationApi and stores the last location based on the last client that had used it. If your app is the first client to use it, it probably will not have gotten the last location as quickly as you call your "OnConnected()" function.

    Here you have some potential options:

    1. Create A Checking Thread
    You could implement a thread that checks for the last known location every X amount of seconds. Then, regardless of whether or not your app was the first to launch, you will eventually receive the last location.
    2. Implement Location Listening
    You could also implement Location Listening in your activity and update your location every time the OnLocationChanged event is fired.

提交回复
热议问题