Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using MonoTouch.CoreLocation;
- using System.Threading.Tasks;
- namespace Polferd.iOS
- {
- public class LocationService : ILocationService
- {
- private CLLocationManager m_LocationManager;
- public LocationService()
- {
- m_LocationManager = new CLLocationManager();
- StartLocationUpdates ();
- }
- public double Latitude ()
- {
- return m_LocationManager.Location.Coordinate.Latitude;
- }
- public double Longitude ()
- {
- return m_LocationManager.Location.Coordinate.Longitude;
- }
- private async void StartLocationUpdates()
- {
- if (CLLocationManager.LocationServicesEnabled) {
- m_LocationManager.DesiredAccuracy = 1;
- await Task.Factory.StartNew(() => m_LocationManager.StartUpdatingLocation());
- // m_LocationManager.StartUpdatingLocation();
- } else {
- Console.WriteLine ("Location services not enabled");
- }
- }
- }
- }
- //I mapPage:
- m_locationService = Container.Singleton<ILocationService>();
- //I AppDelegate:
- container.RegisterSingleton<ILocationService> (new LocationService ());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement