Faster Answers: the Last Known Location

There are times when your users do not want to sit and wait for several minutes for their device to communicate with mysterious satellites in space just to find out where they are. Fortunately, with a little more work, you can prevent them from having to wait by using the LocationManager’s last known location for any location provider.

Since you are using the GPS provider only, it makes the most sense to ask for its last known location, and doing so is rather straightforward. The only other trick is getting that location back to the user interface, and for that you can simply broadcast an Intent just as though you were the LocationManager.

Listing 33.10  Getting the last known location (RunManager.java)

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.