Unable To Get The Location Updates In Monodroid
I am trying to get the location in my Android app as follows LocationManager lmanager = (LocationManager)context.GetSystemService(Context.LocationService); if (lmanager.IsProviderE
Solution 1:
The GetLastKnownLocation()
method returns the last location it knew about, which could be null if it has never received any updates before. I think what you want to do here is listen for location updates, and then respond to them once they come in. You can do this by implementing the ILocationListener
interface:
classMyLocationListener : Java.Lang.Object, ILocationListener
{
publicvoidOnLocationChanged(Location location)
{
}
publicvoidOnProviderDisabled(string provider)
{
}
publicvoidOnProviderEnabled(string provider)
{
}
publicvoidOnStatusChanged(string provider, Availability status, Bundle extras)
{
}
}
In your activity you can declare that you'd like to use this class to start listening for updates like this:
var locationManager = (LocationManager)GetSystemService(LocationService);
var locationListener = new MyLocationListener();
locationManager.RequestLocationUpdates(LocationManager.NetworkProvider, 5000, 2, locationListener);
Post a Comment for "Unable To Get The Location Updates In Monodroid"