Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System;
  2. using Android.App;
  3. using Android.Content;
  4. using Android.Runtime;
  5. using Android.Views;
  6. using Android.Widget;
  7. using Android.OS;
  8. using Android.Locations;
  9. using System.Collections.Generic;
  10. using Android.Util;
  11. using System.Linq;
  12.  
  13. namespace LoyaltyCheckInAndroid
  14. {
  15. [Activity(Label = "LoyaltyCheckIn", MainLauncher = true, Icon = "@drawable/icon")]
  16. public class MainActivity : Activity, ILocationListener
  17. {
  18. Location _currentLocation;
  19. LocationManager _locationManager;
  20.  
  21. string _locationProvider;
  22.  
  23. TextView txtLatitude;
  24. TextView txtLongitude;
  25.  
  26. protected override void OnCreate(Bundle bundle)
  27. {
  28. base.OnCreate(bundle);
  29.  
  30. SetContentView(Resource.Layout.Main);
  31.  
  32. txtLatitude = FindViewById<TextView>(Resource.Id.Latitude);
  33. txtLongitude = FindViewById<TextView>(Resource.Id.Longitude);
  34. FindViewById<TextView>(Resource.Id.btnCheckIn).Click += BtnCheckIn_OnClick;
  35.  
  36. InitializeLocationManager();
  37. }
  38.  
  39. protected override void OnResume()
  40. {
  41. base.OnResume();
  42. string Provider = LocationManager.GpsProvider;
  43.  
  44. if (_locationManager.IsProviderEnabled(Provider))
  45. {
  46. _locationManager.RequestLocationUpdates(Provider, 2000, 1, this);
  47. }
  48. else
  49. {
  50. }
  51. }
  52.  
  53. protected override void OnPause()
  54. {
  55. base.OnPause();
  56. _locationManager.RemoveUpdates(this);
  57. }
  58.  
  59. void BtnCheckIn_OnClick(object sender, EventArgs eventArgs)
  60. {
  61. if (_currentLocation == null)
  62. {
  63. txtLongitude.Text = "???";
  64. txtLatitude.Text = "???";
  65.  
  66. return;
  67. }
  68. //ovde prati za foursqre
  69. txtLatitude.Text = _currentLocation.Latitude.ToString();
  70. txtLongitude.Text = _currentLocation.Longitude.ToString();
  71. }
  72.  
  73. void InitializeLocationManager()
  74. {
  75. _locationManager = GetSystemService(Context.LocationService) as LocationManager;
  76. Criteria locationCriteria = new Criteria();
  77.  
  78. locationCriteria.Accuracy = Accuracy.Coarse;
  79. locationCriteria.PowerRequirement = Power.Medium;
  80.  
  81. _locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
  82.  
  83. if (_locationProvider != null)
  84. {
  85. _locationManager.RequestLocationUpdates(_locationProvider, 2000, 1, this);
  86. }
  87. else
  88. {
  89.  
  90. }
  91. }
  92.  
  93. public void OnLocationChanged(Location location)
  94. {
  95. _currentLocation = location;
  96. }
  97.  
  98. public void OnProviderDisabled(string provider) { }
  99.  
  100. public void OnProviderEnabled(string provider) { }
  101.  
  102. public void OnStatusChanged(string provider, Availability status, Bundle extras) { }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement