How to receive location updates
If your application needs frequent location updates, your application can request periodic updates. This recipe will demonstrate this using the requestLocationUpdates()
method from GoogleApiClient
.
Getting ready
Create a new project in Android Studio and call it: LocationUpdates
. Use the default Phone & Tablet options and select Empty Activity when prompted for Activity Type.
How to do it...
Since we are receiving updates from the system, we won't need a button for this recipe. Our layout will consist of just the TextView
to see the location data. Open the Android Manifest and follow these steps:
- Add the following permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- Open the file
build.gradle (Module: app)
and add the following statement to thedependencies
section:compile 'com.google.android.gms:play-services:8.4.0'
- Open
activity_main.xml
and replace the existingTextView
with the following XML...