// This file has been autogenerated from a class added in the UI designer.

using System;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.CoreLocation;

namespace StoryboardTables
{
	[Register ("GPSLocate")]
   public partial class GPSLocate : UIViewController
	{
      CLLocationManager iPhoneLocationManager = null;

		public GPSLocate (IntPtr handle) : base (handle)
		{
		}

      public override void ViewDidLoad()
      {
         base.ViewDidLoad();
         // load the appropriate view, based on the device type

         // initialize our location manager and callback handler
         iPhoneLocationManager = new CLLocationManager ();
        
         double longdute;
         double latidute;
          // uncomment this if you want to use the delegate pattern:
         //locationDelegate = new LocationDelegate (mainScreen);
         //iPhoneLocationManager.Delegate = locationDelegate;

         // you can set the update threshold and accuracy if you want:
         //iPhoneLocationManager.DistanceFilter = 10; // move ten meters before updating
         //iPhoneLocationManager.HeadingFilter = 3; // move 3 degrees before updating

         // you can also set the desired accuracy:
         iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
         // you can also use presets, which simply evalute to a double value:
         //iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;

         // handle the updated location method and update the UI
         if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
            iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
               UpdateLocation (this, e.Locations [e.Locations.Length - 1]);
               iPhoneLocationManager.StopUpdatingLocation();

              };
         } else {
            // this won't be called on iOS 6 (deprecated)
            iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) =>
            {
               UpdateLocation(this, e.NewLocation);
               iPhoneLocationManager.StopUpdatingLocation();

            };
         }
              
      
         


         // handle the updated heading method and update the UI
         iPhoneLocationManager.UpdatedHeading += (object sender, CLHeadingUpdatedEventArgs e) => {
            //        GPSLocate.LblMagneticHeading.Text = e.NewHeading.MagneticHeading.ToString () + "º";
            // GPSLocate.LblTrueHeading.Text = e.NewHeading.TrueHeading.ToString () + "º";
         };

         // start updating our location, et. al.
         if (CLLocationManager.LocationServicesEnabled)
            iPhoneLocationManager.StartUpdatingLocation ();
         if (CLLocationManager.HeadingAvailable)
            iPhoneLocationManager.StartUpdatingHeading ();

      }
      static public void UpdateLocation (GPSLocate ms, CLLocation newLocation)
      {

         
         ms.LblAltitude.Text = newLocation.Altitude.ToString () + " meters";
         ms.LblLongitude.Text = newLocation.Coordinate.Longitude.ToString () + "º";
         ms.LblLatitude.Text = newLocation.Coordinate.Latitude.ToString () + "º";
         ms.LblCourse.Text = newLocation.Course.ToString () + "º";
         ms.LblSpeed.Text = newLocation.Speed.ToString () + " meters/s";

         // get the distance from here to paris
         ms.LblDistanceToParis.Text = (newLocation.DistanceFrom(new CLLocation(48.857, 2.351)) / 1000).ToString() + " km";
       

         var x1 =Convert.ToDouble( "40.023408"); 
         var y1 =Convert.ToDouble( "40.643127");
         var x2 =Convert.ToDouble( "30.753657");
         var y2 = Convert.ToDouble("30.038635");
         var longdute =newLocation.Coordinate.Longitude;
         var latidute = newLocation.Coordinate.Latitude;

      
         ms.checkIt.Clicked+= (sender, e) => {


            if (longdute > x2 && longdute < x1 && latidute > y2 && latidute < y1)
               new UIAlertView("Ankara Dışındasın", "Konum : " + longdute + " " + latidute, null, "OK", null).Show();
            else
               new UIAlertView("Ankara İçerisindesin", "Konum : " + longdute + " " + latidute, null, "OK", null).Show();

         };


      }
//
//      #region -= protected methods =-
//
//      // Loads either the iPad or iPhone view, based on the current device
//      protected void LoadViewForDevice()
//      {
//         // load the appropriate view based on the device
//         if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
//            mainViewController_iPad = new MainViewController_iPad ();
//            this.View.AddSubview (mainViewController_iPad.View);
//            mainScreen = mainViewController_iPad as IMainScreen;
//         } else {
//            mainViewController_iPhone = new MainViewController_iPhone ();
//            var b = this.View.Bounds;
//            this.View.AddSubview (mainViewController_iPhone.View);
//            mainViewController_iPhone.View.Frame = b; // for 4 inch iPhone5 screen
//            mainScreen = mainViewController_iPhone as IMainScreen;
//         }
//      }
//
//      #endregion








	}
}
