Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static readonly string TAG = "X:" + typeof (Activity1).Name;
- Location _currentLocation;
- LocationManager _locationManager;
- string _locationProvider;
- TextView _locationText;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- _locationText = FindViewById<TextView>(Resource.Id.GpsTest);
- InitializeLocationManager();
- Add700ToCoordinates();
- }
- public void OnLocationChanged(Location location)
- {
- _currentLocation = location;
- if (_currentLocation == null)
- {
- _locationText.Text = "Unable to determine your location. Try again in a short while.";
- }
- else
- {
- _locationText.Text = string.Format("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
- //das her wird ausgegeben bei button.click
- }
- } // ausgabe der koordinaten
- public void OnProviderDisabled(string provider) {}
- public void OnProviderEnabled(string provider) {}
- public void OnStatusChanged(string provider, Availability status, Bundle extras)
- {
- Log.Debug(TAG, "{0}, {1}", provider, status);
- }
- void InitializeLocationManager()
- {
- _locationManager = (LocationManager) GetSystemService(LocationService);
- Criteria criteriaForLocationService = new Criteria
- {
- Accuracy = Accuracy.Fine
- };
- IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
- if (acceptableLocationProviders.Any())
- {
- _locationProvider = acceptableLocationProviders.First();
- }
- else
- {
- _locationProvider = string.Empty;
- }
- Log.Debug(TAG, "Using " + _locationProvider + ".");
- }
- protected override void OnResume()
- {
- base.OnResume();
- _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
- Log.Debug(TAG, "Listening for location updates using " + _locationProvider + ".");
- }
- protected override void OnPause()
- {
- base.OnPause();
- _locationManager.RemoveUpdates(this);
- Log.Debug(TAG, "No longer listening for location updates.");
- }
- public string StringWithLocation(Location location)
- {
- string StringWithCoordinates = "Null";
- _currentLocation = location;
- if (_currentLocation == null)
- {
- StringWithCoordinates = "Unable to determine your location. Try again in a short while.";
- }
- else
- {
- StringWithCoordinates = string.Format("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
- }
- return StringWithCoordinates;
- }
- public void Add700ToCoordinates()
- {
- // StringWithLocation();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement