omega
omega

Reputation: 43893

How fast does getting last known location in android work?

In my android app, I want to get the last known location. I am following this tutorial http://developer.android.com/training/location/retrieve-current.html.

Basically when the activity loads, I display info which is manipulated based on the current location, so I need the location first. I want to know how long it can take for it to get the location or fail trying. Should I attempt to wait and get the location then display the content, or cache the location and then use it so I don't have to wait. ( I prefer no cache)

I don't want the user to wait long, a few seconds is ok i guess.

Also in the 3 callback methods onConnectionSuspended, onConnected and onConnectionFailed, can I be sure that 1 of these will be called no matter what the situation is, (like no internet, no gps, or some random error somewhere)?

Upvotes: 1

Views: 114

Answers (1)

David Wasser
David Wasser

Reputation: 95628

The call to getLastLocation() will return immediately.

The connection to Google Play Services may take some time to succeed or fail, you can never be sure. You might want to show a Dialog to the user while you are waiting for the connection.

You will definitely call a callback on either onConnected() or onConnectionFailed(). You can rely on that.

Upvotes: 1

Related Questions