Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. static readonly string TAG = "X:" + typeof (Activity1).Name;
  2. Location _currentLocation;
  3. LocationManager _locationManager;
  4.  
  5. string _locationProvider;
  6. TextView _locationText;
  7.  
  8. protected override void OnCreate(Bundle bundle)
  9. {
  10. base.OnCreate(bundle);
  11. SetContentView(Resource.Layout.Main);
  12.  
  13. _locationText = FindViewById<TextView>(Resource.Id.GpsTest);
  14.  
  15. InitializeLocationManager();
  16.  
  17. Add700ToCoordinates();
  18. }
  19.  
  20. public void OnLocationChanged(Location location)
  21. {
  22.  
  23. _currentLocation = location;
  24. if (_currentLocation == null)
  25. {
  26. _locationText.Text = "Unable to determine your location. Try again in a short while.";
  27. }
  28. else
  29. {
  30. _locationText.Text = string.Format("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
  31. //das her wird ausgegeben bei button.click
  32. }
  33.  
  34. } // ausgabe der koordinaten
  35.  
  36. public void OnProviderDisabled(string provider) {}
  37.  
  38. public void OnProviderEnabled(string provider) {}
  39.  
  40. public void OnStatusChanged(string provider, Availability status, Bundle extras)
  41. {
  42. Log.Debug(TAG, "{0}, {1}", provider, status);
  43. }
  44.  
  45. void InitializeLocationManager()
  46. {
  47. _locationManager = (LocationManager) GetSystemService(LocationService);
  48. Criteria criteriaForLocationService = new Criteria
  49. {
  50. Accuracy = Accuracy.Fine
  51. };
  52. IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
  53.  
  54. if (acceptableLocationProviders.Any())
  55. {
  56. _locationProvider = acceptableLocationProviders.First();
  57. }
  58. else
  59. {
  60. _locationProvider = string.Empty;
  61. }
  62. Log.Debug(TAG, "Using " + _locationProvider + ".");
  63. }
  64.  
  65. protected override void OnResume()
  66. {
  67. base.OnResume();
  68. _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
  69. Log.Debug(TAG, "Listening for location updates using " + _locationProvider + ".");
  70. }
  71.  
  72. protected override void OnPause()
  73. {
  74. base.OnPause();
  75. _locationManager.RemoveUpdates(this);
  76. Log.Debug(TAG, "No longer listening for location updates.");
  77. }
  78.  
  79. public string StringWithLocation(Location location)
  80. {
  81. string StringWithCoordinates = "Null";
  82.  
  83. _currentLocation = location;
  84. if (_currentLocation == null)
  85. {
  86. StringWithCoordinates = "Unable to determine your location. Try again in a short while.";
  87. }
  88. else
  89. {
  90. StringWithCoordinates = string.Format("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
  91. }
  92.  
  93. return StringWithCoordinates;
  94.  
  95. }
  96.  
  97. public void Add700ToCoordinates()
  98. {
  99. // StringWithLocation();
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement