Recipe Updating Location Upon Change

The LocationListener interface is used to receive notifications when the location has changed.The location manager's requestLocationUpdates() method needs to be called after a location provider is initialized to specify when the current activity is to be notified of changes. It depends on the following parameters:

■ provider—The location provider the application uses.

■ minTime—The minimum time between updates in milliseconds (although the system might increase this time to conserve power).

■ minDistance—The minimum distance change before updates in meters.

■ listener—The location listener should receive the updates.

The location listener's onLocationChanged() method can be overridden to specify an action to be done with the new location. Listing 10.4 shows how this is put together for 5 seconds of time and changes of more than 2 meters between updates.An actual implementation should use larger values between updates to save battery life. Also note that no heavy processing should be done in the onLocationChanged() method. Rather, copy the data and pass it off to a thread.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment