Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System;
  2. using MonoTouch.CoreLocation;
  3. using System.Threading.Tasks;
  4.  
  5. namespace Polferd.iOS
  6. {
  7. public class LocationService : ILocationService
  8. {
  9. private CLLocationManager m_LocationManager;
  10.  
  11. public LocationService()
  12. {
  13. m_LocationManager = new CLLocationManager();
  14. StartLocationUpdates ();
  15. }
  16.  
  17. public double Latitude ()
  18. {
  19. return m_LocationManager.Location.Coordinate.Latitude;
  20. }
  21.  
  22. public double Longitude ()
  23. {
  24. return m_LocationManager.Location.Coordinate.Longitude;
  25. }
  26.  
  27. private async void StartLocationUpdates()
  28. {
  29.  
  30. if (CLLocationManager.LocationServicesEnabled) {
  31.  
  32. m_LocationManager.DesiredAccuracy = 1;
  33. await Task.Factory.StartNew(() => m_LocationManager.StartUpdatingLocation());
  34. // m_LocationManager.StartUpdatingLocation();
  35. } else {
  36. Console.WriteLine ("Location services not enabled");
  37. }
  38. }
  39.  
  40. }
  41. }
  42.  
  43. //I mapPage:
  44.  
  45. m_locationService = Container.Singleton<ILocationService>();
  46.  
  47. //I AppDelegate:
  48.  
  49. container.RegisterSingleton<ILocationService> (new LocationService ());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement