How do i get my last known location in android?

前端 未结 3 1390
一个人的身影
一个人的身影 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:37

    First onConnected does not get called immediately. It takes some time depending on various factors. So keep a log statement and check when onConnected is called.

    Also if the device location is turned off then you will never receive any data back. It will be null.

    Also it is not necessary that the google api client will hold your last location irrespective of whether you are connected to internet or not. It might and it might not. It only caches the last location and cache can be cleared anytime by the android OS.

提交回复
热议问题