private TextView locationText; private Location currentLocation; private LocationManager locationManager; private string locationProvider; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); locationText = FindViewById<TextView>(Resource.Id.location); locationManager = (LocationManager)GetSystemService(LocationService); Criteria locationServiceCriteria = new Criteria { Accuracy = Accuracy.Coarse }; IList<string> acceptableLocationProviders = locationManager.GetProviders(locationServiceCriteria,true); if (acceptableLocationProviders.Any()) { locationProvider = acceptableLocationProviders.First(); } else { locationText.Text = "No location provider!"; } } protected override void OnResume() { base.OnResume(); locationManager.RequestLocationUpdates(locationProvider,0,0,this); } protected override void OnPause() { base.OnPause(); locationManager.RemoveUpdates(this); } public void OnLocationChanged(Location location) { currentLocation = location; if (location == null) { locationText.Text = "Location not found!"; } else { locationText.Text = string.Format("{0},{1}", currentLocation.Latitude, currentLocation.Longitude); } } public void OnProviderDisabled(string provider) { } public void OnProviderEnabled(string provider) { } public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)