Receiving Location Updates

When you need more current information and want to know when the location changes, you can register for periodic location updates by using the requestLocationUpdates() method of the LocationManager class. This method allows an activity to listen to events from a specific provider (for example, the best provider given your criteria). This frequency of notifications can be adjusted by specifying the minimum time (in milliseconds) and the minimum distance interval (in meters) between updates.

To receive a notification when the location changes, you should have the interested activity implement the LocationListener (android.location.LocationListener) interface. This interface has a number of helpful callback methods, which allow the activity to react when the provider is enabled and disabled, when its status changes, and when the location changes.

Resolving the current location can take some time. Therefore, you'll want to consider putting most LBS calls in a worker thread separate from the main UI thread (or writing a background service to support your application). We will discuss threading later in this book.

0 0

Post a comment