Reputation: 1
I have an activity that needs to display an alert to user when location is updated,
but i need first to get current location (update last known location) and then start a location update listener to display alert in this activity.
Basically what i need is to display an alert if location changed from time activity was created.
If i use getLastKnownLocation when activity is created, it might be outdated, then the requestLocationUpdate listener is called a few seconds from activity creation time.
How can i do this?
Thanks in advance,
Upvotes: 0
Views: 2450
Reputation: 673
Check Blow Link.. May be it's help you... In that u have to pass sach argument so that Location manager can easily Update Your Location and your code is also right to get Location ....
Upvotes: 1
Reputation: 7029
Getting last known location (quickly)
LocationProvider locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDER
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
from ( http://developer.android.com/guide/topics/location/obtaining-user-location.html#FastFix )
Listen for location updates: http://developer.android.com/guide/topics/location/obtaining-user-location.html#Updates
This is the functionality you can use. But know that last location might be pretty old and inaccurate. Depends on when a application was trying to get the location the last time. But it normally should be somewhere in the area you are.
If that is not good enough, than you will have to do something like this:
I hope this helps.
Upvotes: 3