How to get the last location
We'll start this chapter with a simple recipe that is commonly needed: how to get the last known location. This is an easy way to use APIs with very little overhead resource drain. (This means, your app won't be responsible for killing the battery.)
This recipe also provides a good introduction to setting up the Google Location APIs.
Getting ready
Create a new project in Android Studio and call it: GetLastLocation
. Use the default Phone & Tablet options, and select Empty Activity when prompted for Activity Type.
How to do it...
First, we'll add the necessary permissions to the Android Manifest, then we'll create a layout with a Button
and a TextView
element. Finally, we'll create a GoogleAPIClient
API to access the last ...
Get Android Application Development Cookbook - Second Edition 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.