public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            buttonLocation.TouchUpInside += (sender, e) => {
                var locator = new Geolocator { DesiredAccuracy = 50 };
                locator.GetPositionAsync (timeout: 10000).ContinueWith (t => {
                    var text = String.Format("Lat: {0}, Long: {0}", t.Result.Latitude, t.Result.Longitude);
                    InvokeOnMainThread(() => LabelLocation.Text = text);
                });
            };

            buttonPicture.TouchUpInside += (sender, e) => {
                var camera = new MediaPicker ();

                if (!camera.IsCameraAvailable) {
                    Console.WriteLine("Camera unavailable!");
                    return;
                }

                var opts = new StoreCameraMediaOptions {
                    Name = "test.jpg",
                    Directory = "MiniHackDemo"
                };

                camera.TakePhotoAsync (opts).ContinueWith (t => {
                    if (t.IsCanceled)
                        return;

                    InvokeOnMainThread(() => imagePhoto.Image = UIImage.FromFile(t.Result.Path));
                });
            };
        }
예제 #2
0
 private async Task GetLocation()
 {
     var locator = new Geolocator(this) { DesiredAccuracy = 50 };
    
     var location = await locator.GetPositionAsync(10000);
     MineAppServices.Current.CurrentPosition = location;
 }
예제 #3
0
		public async Task<TripLog.Models.GeoCoords> GetGeoCoordinatesAsync ()
		{
			var locator = new Geolocator{ DesiredAccuracy = 30 };

			var position = await locator.GetPositionAsync (30000);
			var result = new GeoCoords{
				Latitude = position.Latitude,
				Longitude = position.Longitude
			};
			return result;
		}
예제 #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.buttonLocation);
            LabelLocation = FindViewById<TextView>(Resource.Id.locationLabel);
            image = FindViewById<ImageView>(Resource.Id.imagePhoto);

            button.Click += delegate {

                var locator = new Geolocator(this) { DesiredAccuracy = 50 };
                locator.GetPositionAsync(timeout: 10000).ContinueWith(t =>
                {
                    var text = String.Format("Location : Lat: {0}, Long: {0}", t.Result.Latitude, t.Result.Longitude);
                    this.RunOnUiThread(() => LabelLocation.Text = text);
                });
            };

            Button getimge = FindViewById<Button>(Resource.Id.buttonCamera);
            getimge.Click += delegate
            {
                var camera = new MediaPicker(this);

                if (!camera.IsCameraAvailable)
                {
                    Console.WriteLine("Camera unavailable!");
                    return;
                }

                var opts = new StoreCameraMediaOptions
                {
                    Name = "test.jpg",
                    Directory = "MiniHackDemo"
                };

                camera.TakePhotoAsync(opts).ContinueWith(t =>
                {
                    if (t.IsCanceled)
                        return;

                    using (var bmp = Android.Graphics.BitmapFactory.DecodeFile(t.Result.Path))
                    {
                        this.RunOnUiThread(() => image.SetImageBitmap(bmp));
                    }
                });
                
            };
        }
예제 #5
0
        public System.Threading.Tasks.Task<GeoTwitter.Tools.TwitterPosition> GetCurrentPosition()
        {
            return Task.Run(
                        async () =>
                            {
                                var geo = new Geolocator(Android.App.Application.Context);

                                var result = await geo.GetPositionAsync(1000);

                                return new TwitterPosition { Latitude = result.Latitude, Longitude = result.Longitude };
                            });
        }
        public async Task<GPSCoordinates> GetCurrentCoordinates()
        {
            var locator = new Geolocator() { DesiredAccuracy = 50 };
            var coordinates = new GPSCoordinates();
            if (locator.IsGeolocationEnabled && locator.IsGeolocationEnabled)
            {
                var pos = await locator.GetPositionAsync(timeout: 10000);
                coordinates.Latitude = pos.Latitude;
                coordinates.Longitude = pos.Longitude;
            }

            return coordinates;
        }
		public async Task<Coordinates> GetCoordinatesAsync()
		{
			var locator = new Geolocator(Forms.Context) { DesiredAccuracy = 30 };
			var position = await locator.GetPositionAsync(30000);

			var result = new Coordinates
			{
				Latitude = position.Latitude,
				Longitude = position.Longitude
			};

			return result;
		}
		public async Task<Coordinates> GetCoordinatesAsync()
		{
			var locator = new Geolocator() {DesiredAccuracy = 50};
			var position = await locator.GetPositionAsync(30000);

			var coords = new Coordinates
			{
				Latitude = position.Latitude,
				Longitude = position.Longitude
			};

			return coords;
		}
        public async Task<GeoCoords> GetLocationAsync()
        {
            var locator = new Geolocator(this._appContext) { DesiredAccuracy = 30 };
            var position = await locator.GetPositionAsync(30000);

            var result = new GeoCoords
            {
                Latitude = position.Latitude,
                Longitude = position.Longitude
            };

            return result;
        }
예제 #10
0
        private async void LoadViewControllers()
        {
            Forms.Init();

            window = new UIWindow(UIScreen.MainScreen.Bounds);
            var locator = new Geolocator() { DesiredAccuracy = 20 };

            var location = await locator.GetPositionAsync(10000);

            window.RootViewController = App.GetMainPage().CreateViewController();

            window.MakeKeyAndVisible();

        }
예제 #11
0
		async void GetPosition()
		{
			try 
			{
				locator = new Geolocator{DesiredAccuracy =50};
				if ( locator.IsListening != true )
					locator.StartListening(minTime: 1000, minDistance: 0);
				position = await locator.GetPositionAsync (timeout: 20000);
			}

			catch ( Exception e) 
			{

			}
		}
예제 #12
0
        public static IObservable<Position> GetPosition(bool includeHeading = false)
        {
            if (Implementation != null) {
                return Implementation.GetPosition(includeHeading);
            }

            #if !WP7 && !WP8
            var ret = Observable.Create<Position>(subj => {
                var geo = new Geolocator();
                var cts = new CancellationTokenSource();
                var disp = new CompositeDisposable();

                if (!geo.IsGeolocationAvailable || !geo.IsGeolocationEnabled) {
                    return Observable.Throw<Position>(new Exception("Geolocation isn't available")).Subscribe(subj);
                }

                disp.Add(new CancellationDisposable(cts));
                disp.Add(geo.GetPositionAsync(cts.Token, includeHeading).ToObservable().Subscribe(subj));
                return disp;
            }).Multicast(new AsyncSubject<Position>());
            #else
            // NB: Xamarin.Mobile.dll references CancellationTokenSource, but
            // the one we have comes from the BCL Async library - if we try to
            // pass in our type into the Xamarin library, it gets confused.
            var ret = Observable.Create<Position>(subj => {
                var geo = new Geolocator();
                var disp = new CompositeDisposable();

                if (!geo.IsGeolocationAvailable || !geo.IsGeolocationEnabled) {
                    return Observable.Throw<Position>(new Exception("Geolocation isn't available")).Subscribe(subj);
                }

                disp.Add(geo.GetPositionAsync(Int32.MaxValue, includeHeading).ToObservable().Subscribe(subj));
                return disp;
            }).Multicast(new AsyncSubject<Position>());
            #endif

            return ret.RefCount();
        }
        public async Task<LocationCoordinates> GetCurrentLocation()
        {
            EventHandler<PositionEventArgs> handler = null;
            var result = new LocationCoordinates();
            TaskCompletionSource<LocationCoordinates> tcs = new TaskCompletionSource<LocationCoordinates>();
            Geolocator locator = new Geolocator { DesiredAccuracy = 50 };

            try
            {
                if (!locator.IsListening)
                {
                    locator.StartListening(10, 100);    
                }                

                handler = (object sender, PositionEventArgs e) =>
                {
                    result.Status = e.Position.Timestamp;
                    result.Latitude = e.Position.Latitude;
                    result.Longitude = e.Position.Longitude;
                    locator.PositionChanged -= handler;
                    tcs.SetResult(result);
                };
                locator.PositionChanged += handler;                
                
                await locator.GetPositionAsync(timeout: 10000).ContinueWith(
                    t =>
                    {
                    });               
            }
            catch (System.Exception ex)
            {
                if (ex.InnerException.GetType().ToString() == "Xamarin.Geolocation.GeolocationException")
                {
                    tcs.SetException(ex);
                }
            }

            return tcs.Task.Result;
        }
		public async Task<CoffeeRadar.Core.Models.GeoCoords> GetGeoCoordinatesAsync ()
		{
			try
			{
			var locator = new Geolocator() {DesiredAccuracy = 30};
			var position = await locator.GetPositionAsync(30000);

			var result = new GeoCoords
			{
				Latitude = position.Latitude,
				Longitude = position.Longitude
			};

			return result;
			}
			catch (Exception e) 
			{

			}

			return null;
		}
예제 #15
0
		protected override async void OnResume ()
		{
			base.OnResume ();

			int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0);
			if(itemId > 0) {
				shareItem = App.Database.GetItem(itemId);

				fileName = shareItem.ImagePath;
				Console.WriteLine ("Image path: {0}", fileName);
				Bitmap b = BitmapFactory.DecodeFile (fileName);
				// Display the bitmap
				photoImageView.SetImageBitmap (b);
				locationText.Text = shareItem.Location;
				return;
			}

			if (string.IsNullOrEmpty (fileName)) {
				fileName = "in-progress";
				var picker = new MediaPicker (this);
				if (!picker.IsCameraAvailable) {
					Console.WriteLine ("No camera!");
				} else {
					var options = new StoreCameraMediaOptions {
						Name = DateTime.Now.ToString ("yyyyMMddHHmmss"),
						Directory = "MediaPickerSample"
					};

					if (!picker.IsCameraAvailable || !picker.PhotosSupported) {
						ShowUnsupported();
						return;
					}

					Intent intent = picker.GetTakePhotoUI (options);

					StartActivityForResult (intent, 1);
				}
			} else {
				SetImage ();
			}

			try {
				var locator = new Geolocator (this) {
					DesiredAccuracy = 50
				};
				var position = await locator.GetPositionAsync (10000);
				Console.WriteLine ("Position Latitude: {0}", position.Latitude);
				Console.WriteLine ("Position Longitude: {0}", position.Longitude);

				location = string.Format ("{0},{1}", position.Latitude, position.Longitude);
				locationText.Text = location;
			} catch (Exception e) {
				Console.WriteLine ("Position Exception: {0}", e.Message);
			}
		}
예제 #16
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            //			locator = new Geolocator{ DesiredAccuracy = 50 };
            //
            //			locator.StartListening(5000, 1, false);
            //			locator.PositionChanged += (object sender, PositionEventArgs e) => {
            //				Console.WriteLine ("Position Status: {0}", e.Position.Accuracy);
            //				Console.WriteLine ("Position Latitude: {0}", e.Position.Latitude);
            //				Console.WriteLine ("Position Longitude: {0}", e.Position.Longitude);
            //			};
            //			locator.PositionError += (object sender, PositionErrorEventArgs e) => {
            //				Console.WriteLine("Could not find position: {0}, {1}", e.Error, e.ToString() );
            //			};

            actIndicator.Hidden = true;
            mapView.MapType = MKMapType.Standard;

            var clm = new CLLocationManager();
            clm.RequestAlwaysAuthorization();

            mapView.ShowsUserLocation = true;

            //currLocation = new CLLocationCoordinate2D(20.7592, -156.4572);

            // C# style event handler - can access class instance variables
            mapView.DidUpdateUserLocation += (object sender, MKUserLocationEventArgs e) =>
            {
                Console.WriteLine(".NET Lat: {0}, Long: {1}, Alt: {2}", e.UserLocation.Coordinate.Latitude, e.UserLocation.Coordinate.Longitude, e.UserLocation.Location.Altitude);
                currLocation = e.UserLocation.Coordinate;
                if (firstLaunch) {
                    mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true);
                    firstLaunch = false;
                }
                else
                    mapView.SetCenterCoordinate(currLocation, true);
            };

            mapView.DidSelectAnnotationView += (object sender, MKAnnotationViewEventArgs e) =>
            {
                var annotation = e.View.Annotation as BNRMapPoint;

                if (annotation != null) {
                    Console.WriteLine(".NET DidSelectAnnotationView: {0}", annotation.Title);
                }

            };

            // Strong Delegate method. Create delegate class as nested class of ViewCOntroller
            // Override need methods in that nested delegate class
            //			mapDelegate = new WhereAmIMapDelegate();
            //			mapView.Delegate = mapDelegate;

            // Weak delegate method. use Export attribute with selector to override then implement method.
            // Whichever is assigned last wins and kills the other.
            //			mapView.WeakDelegate =  this;

            //			textField.Delegate = new TextFieldDelegate();

            textField.EditingDidEndOnExit += (object sender, EventArgs e) =>
            {
                actIndicator.Hidden = false;
                if (!firstLaunch) {
                    BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation);
                    mapView.AddAnnotation(mp);
                    textField.ResignFirstResponder();
                    textField.Text = "";
                    actIndicator.Hidden = true;
                }
                else {
                    var locator = new Geolocator{ DesiredAccuracy = 50 };
                    locator.GetPositionAsync (timeout: 10000).ContinueWith (t => {
                        CLLocationCoordinate2D coord = new CLLocationCoordinate2D(t.Result.Latitude, t.Result.Longitude);
                        currLocation = coord;
                        MKCoordinateRegion region = MKCoordinateRegion.FromDistance(currLocation, 250, 250);
                        mapView.SetRegion(region, true);
                        BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation);
                        mapView.AddAnnotation(mp);
                        textField.ResignFirstResponder();
                        textField.Text = "";
                        actIndicator.Hidden = true;
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }

            };

            segControl.BackgroundColor = UIColor.White;
            segControl.ValueChanged += (object sender, EventArgs e) =>
            {
                switch (segControl.SelectedSegment)
                {
                    case 0:
                        mapView.MapType = MKMapType.Standard;
                        break;
                    case 1:
                        mapView.MapType = MKMapType.Satellite;
                        break;
                    case 2:
                        mapView.MapType = MKMapType.Hybrid;
                        break;
                    default:
                        break;

                }
            };
        }
예제 #17
0
		public override async void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);

			if (fileName == "") {
				fileName = "in-progress";
				var picker = new MediaPicker ();
				//           new MediaPicker (this); on Android
				if (!picker.IsCameraAvailable || !picker.PhotosSupported)
					Console.WriteLine ("No camera!");
				else {
					var options = new StoreCameraMediaOptions {
						Name = DateTime.Now.ToString("yyyyMMddHHmmss"),
						Directory = "MediaPickerSample"
					};
#if !VISUALSTUDIO
					#region new style
					pickerController = picker.GetTakePhotoUI (options);
					PresentViewController (pickerController, true, null);

					var pickerTask = pickerController.GetResultAsync ();
					await pickerTask;

					// We need to dismiss the controller ourselves
					await DismissViewControllerAsync (true); // woot! async-ified iOS method

					// User canceled or something went wrong
					if (pickerTask.IsCanceled || pickerTask.IsFaulted)
						return;

					// We get back a MediaFile
					MediaFile media = pickerTask.Result;
					fileName = media.Path;
					PhotoImageView.Image = new UIImage (fileName);
					SavePicture(fileName);

					#endregion
#else
					#region old style (deprecated)
					var t = picker.TakePhotoAsync (options); //.ContinueWith (t => {
					await t;
					if (t.IsCanceled) {
						Console.WriteLine ("User canceled");
						fileName = "cancelled";
						//InvokeOnMainThread(() =>{
						NavigationController.PopToRootViewController(false);
						//});
						return;
					}
					Console.WriteLine (t.Result.Path);
					fileName = t.Result.Path;
					//InvokeOnMainThread(() =>{
					PhotoImageView.Image = new UIImage (fileName);
					//});
					SavePicture(fileName);
					//});
					#endregion
#endif
				}
			} else if (fileName == "cancelled") {
				NavigationController.PopToRootViewController (true);
			} else {
				// populate screen with existing item
				PhotoImageView.Image = new UIImage (fileName);
				LocationText.Text = location;
			}

			var locator = new Geolocator { DesiredAccuracy = 50 };
			//            new Geolocator (this) { ... }; on Android
			var position = await locator.GetPositionAsync (timeout: 10000); //.ContinueWith (p => {
			Console.WriteLine ("Position Latitude: {0}", position.Latitude);
			Console.WriteLine ("Position Longitude: {0}", position.Longitude);

			location = string.Format("{0},{1}", position.Latitude, position.Longitude);

			LocationText.Text = location;
		}
예제 #18
0
		public override async void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);

			if (fileName == "") {
				fileName = "in-progress";
				var picker = new MediaPicker ();
				//           new MediaPicker (this); on Android
				if (!picker.IsCameraAvailable || !picker.PhotosSupported)
					Console.WriteLine ("No camera!");
				else {
					var options = new StoreCameraMediaOptions {
						Name = DateTime.Now.ToString("yyyyMMddHHmmss"),
						Directory = "MediaPickerSample"
					};

					pickerController = picker.GetTakePhotoUI (options);
					PresentViewController (pickerController, true, null);

					MediaFile media;

					try 
					{
						var pickerTask = pickerController.GetResultAsync ();
						await pickerTask;

						// User canceled or something went wrong
						if (pickerTask.IsCanceled || pickerTask.IsFaulted) {
							fileName = "";
							return;
						}

						media = pickerTask.Result;
						fileName = media.Path;

						// We need to dismiss the controller ourselves
						await DismissViewControllerAsync (true); // woot! async-ified iOS method
					}
					catch(AggregateException ae) {
						fileName = "";
						Console.WriteLine("Error while huh", ae.Message);
					} catch(Exception e) {
						fileName = "";
						Console.WriteLine("Error while cancelling", e.Message);
					}

					if (String.IsNullOrEmpty (fileName)) {
						await DismissViewControllerAsync (true); 
					} else {
						PhotoImageView.Image = new UIImage (fileName);
						SavePicture(fileName);
					}
            	}
			}  
			else if (fileName == "cancelled") {
				NavigationController.PopToRootViewController (true);
			} else {
				// populate screen with existing item
				PhotoImageView.Image = FileExists(fileName) ? new UIImage (fileName) : null;
				LocationText.Text = location;
			}

			var locator = new Geolocator { DesiredAccuracy = 50 };
			var position = await locator.GetPositionAsync ( new CancellationToken(), false);
			Console.WriteLine ("Position Latitude: {0}", position.Latitude);
			Console.WriteLine ("Position Longitude: {0}", position.Longitude);

			location = string.Format("{0},{1}", position.Latitude, position.Longitude);

			LocationText.Text = location;
		}
예제 #19
0
        ///Returns double array of user location, {latitude,longitude}; returns {0,0} if location not found
        public async Task<double[]> GetLocation() {
            double[] location={0,0};

            System.Diagnostics.Debug.WriteLine("mydebug--started getting position");

            var locator = new Geolocator(MainActivity.Instance) { DesiredAccuracy = 50 };
            await locator.GetPositionAsync(timeout: 10000).ContinueWith(t =>
            {
                System.Diagnostics.Debug.WriteLine("mydebug--Position Status: {0}", t.Result.Timestamp);
                System.Diagnostics.Debug.WriteLine("mydebug--Position Latitude: {0}", t.Result.Latitude);
                System.Diagnostics.Debug.WriteLine("mydebug--Position Longitude: {0}", t.Result.Longitude);

                //save the location for return
                location[0] = t.Result.Latitude;
                location[1] = t.Result.Longitude;
                
            }, TaskScheduler.FromCurrentSynchronizationContext());

            return location;
        }
예제 #20
0
		protected override async void OnResume ()
		{
			base.OnResume ();

			int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0);
			if(itemId > 0) {
				shareItem = App.Database.GetItem(itemId);

				fileName = shareItem.ImagePath;
				System.Console.WriteLine("Image path: " + fileName);
				Bitmap b = BitmapFactory.DecodeFile (fileName);
				// Display the bitmap
				photoImageView.SetImageBitmap (b);
				locationText.Text = shareItem.Location;
				return;
			}

			if (fileName == "") {
				fileName = "in-progress";
				var picker = new MediaPicker (this);
				//           new MediaPicker (); on iOS
				if (!picker.IsCameraAvailable)
					System.Console.WriteLine ("No camera!");
				else {
					var options = new StoreCameraMediaOptions {
						Name = DateTime.Now.ToString("yyyyMMddHHmmss"),
						Directory = "MediaPickerSample"
					};
#if !VISUALSTUDIO
					#region new style
					if (!picker.IsCameraAvailable || !picker.PhotosSupported) {
						ShowUnsupported();
						return;
					}

					Intent intent = picker.GetTakePhotoUI (options);

					StartActivityForResult (intent, 1);
					#endregion
#else 
					#region old style (deprecated)
					var t = picker.TakePhotoAsync (options); 
					await t;
					if (t.IsCanceled) {
						System.Console.WriteLine ("User canceled");
						fileName = "cancelled";
						// TODO: return to main screen
						StartActivity(typeof(MainScreen));
						return;
					}
					System.Console.WriteLine (t.Result.Path);
					fileName = t.Result.Path;
					fileNameThumb = fileName.Replace(".jpg", "_thumb.jpg"); 

					Bitmap b = BitmapFactory.DecodeFile (fileName);
					RunOnUiThread (() =>
					               {
						// Display the bitmap
						photoImageView.SetImageBitmap (b);

						// Cleanup any resources held by the MediaFile instance
						t.Result.Dispose();
					});
					var boptions = new BitmapFactory.Options {OutHeight = 128, OutWidth = 128};
					var newBitmap = await BitmapFactory.DecodeFileAsync (fileName, boptions);
					var @out = new System.IO.FileStream(fileNameThumb, System.IO.FileMode.Create);
					newBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 90, @out);
					//});
					#endregion
#endif
				}
			} 

			try {
				var locator = new Geolocator (this) { DesiredAccuracy = 50 };
				//            new Geolocator () { ... }; on iOS
				var position = await locator.GetPositionAsync (timeout: 10000);
				System.Console.WriteLine ("Position Latitude: {0}", position.Latitude);
				System.Console.WriteLine ("Position Longitude: {0}", position.Longitude);

				location = string.Format("{0},{1}", position.Latitude, position.Longitude);
				locationText.Text = location;
			} catch (Exception e) {
				System.Console.WriteLine ("Position Exception: " + e.Message);
			}
		}
예제 #21
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var documentDirectories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);
            string documentDirectory = documentDirectories[0];
            string path = Path.Combine(documentDirectory, "annotations.archive");
            Console.WriteLine("Path: {0}", path);

            var annotations = (NSMutableArray)NSKeyedUnarchiver.UnarchiveFile(path);
            if (annotations != null) {
                for (int i = 0; i < annotations.Count; i++) {
                    mapView.AddAnnotation(annotations.GetItem<BNRMapPoint>(i));
                }
            }

            // Perform any additional setup after loading the view, typically from a nib.
            //			locator = new Geolocator{ DesiredAccuracy = 50 };
            //
            //			locator.StartListening(5000, 1, false);
            //			locator.PositionChanged += (object sender, PositionEventArgs e) => {
            //				Console.WriteLine ("Position Status: {0}", e.Position.Accuracy);
            //				Console.WriteLine ("Position Latitude: {0}", e.Position.Latitude);
            //				Console.WriteLine ("Position Longitude: {0}", e.Position.Longitude);
            //			};
            //			locator.PositionError += (object sender, PositionErrorEventArgs e) => {
            //				Console.WriteLine("Could not find position: {0}, {1}", e.Error, e.ToString() );
            //			};

            var clm = new CLLocationManager();
            clm.RequestAlwaysAuthorization();

            actIndicator.StartAnimating();
            gettingLocLabel.Hidden = false;
            textField.Enabled = false;

            int mapTypeValue = NSUserDefaults.StandardUserDefaults.IntForKey(WhereamiMapTypePrefKey);

            segControl.SelectedSegment = mapTypeValue;

            mapView.MapType = (MKMapType)mapTypeValue;
            mapView.ShowsUserLocation = true;
            mapView.ZoomEnabled = true;

            CLLocationCoordinate2D  lastLoc = new CLLocationCoordinate2D(NSUserDefaults.StandardUserDefaults.DoubleForKey(WhereamiLastLocLatPrefKey),NSUserDefaults.StandardUserDefaults.DoubleForKey(WhereamiLastLocLongPrefKey));
            MKCoordinateRegion lastRegion = new MKCoordinateRegion(lastLoc, new MKCoordinateSpan(0.0025, 0.0025));
            mapView.SetRegion(lastRegion, true);

            //currLocation = new CLLocationCoordinate2D(20.7592, -156.4572);

            // C# style event handler - can access class instance variables
            mapView.DidUpdateUserLocation += (object sender, MKUserLocationEventArgs e) =>
            {
                actIndicator.StopAnimating();
                gettingLocLabel.Hidden = true;
                textField.Enabled = true;
                Console.WriteLine(".NET Lat: {0}, Long: {1}, Alt: {2}", e.UserLocation.Coordinate.Latitude, e.UserLocation.Coordinate.Longitude, e.UserLocation.Location.Altitude);
                currLocation = e.UserLocation.Coordinate;
                if (firstLaunch) {
                    mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true);
                    firstLaunch = false;
                }
                else
                    mapView.SetCenterCoordinate(currLocation, true);
            };

            mapView.DidFailToLocateUser += (object sender, NSErrorEventArgs e) => {
                Console.WriteLine("Could not find location: {0}", e.ToString());
                actIndicator.StartAnimating();
                gettingLocLabel.Hidden = false;
                textField.Enabled = false;
            };

            mapView.DidSelectAnnotationView += (object sender, MKAnnotationViewEventArgs e) =>
            {
                var annotation = e.View.Annotation as BNRMapPoint;

                if (annotation != null) {
                    Console.WriteLine(".NET DidSelectAnnotationView: {0}", annotation.Title);
                }

            };

            // Strong Delegate method. Create delegate class as nested class of ViewCOntroller
            // Override need methods in that nested delegate class
            //			mapDelegate = new WhereAmIMapDelegate();
            //			mapView.Delegate = mapDelegate;

            // Weak delegate method. use Export attribute with selector to override then implement method.
            // Whichever is assigned last wins and kills the other.
            //			mapView.WeakDelegate =  this;

            //			textField.Delegate = new TextFieldDelegate();

            textField.EditingDidEndOnExit += (object sender, EventArgs e) =>
            {
                actIndicator.Hidden = false;
                if (!firstLaunch) {
                    BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation);

                    NSUserDefaults.StandardUserDefaults.SetDouble(currLocation.Latitude, WhereamiLastLocLatPrefKey);
                    NSUserDefaults.StandardUserDefaults.SetDouble(currLocation.Longitude, WhereamiLastLocLongPrefKey);

                    mapView.AddAnnotation(mp);
                    textField.ResignFirstResponder();
                    textField.Text = "";
                    actIndicator.Hidden = true;
                }
                else {
                    var locator = new Geolocator{ DesiredAccuracy = 50 };
                    locator.GetPositionAsync (timeout: 10000).ContinueWith (t => {
                        CLLocationCoordinate2D coord = new CLLocationCoordinate2D(t.Result.Latitude, t.Result.Longitude);
                        currLocation = coord;
                        MKCoordinateRegion region = MKCoordinateRegion.FromDistance(currLocation, 250, 250);
                        mapView.SetRegion(region, true);
                        BNRMapPoint mp = new BNRMapPoint(textField.Text, currLocation);

                        NSUserDefaults.StandardUserDefaults.SetDouble(currLocation.Latitude, WhereamiLastLocLatPrefKey);
                        NSUserDefaults.StandardUserDefaults.SetDouble(currLocation.Longitude, WhereamiLastLocLongPrefKey);

                        mapView.AddAnnotation(mp);
                        textField.ResignFirstResponder();
                        textField.Text = "";
                        actIndicator.Hidden = true;
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }

            };

            segControl.BackgroundColor = UIColor.White;
            segControl.ValueChanged += (object sender, EventArgs e) =>
            {
                NSUserDefaults.StandardUserDefaults.SetInt(segControl.SelectedSegment, WhereamiMapTypePrefKey);

                switch (segControl.SelectedSegment)
                {
                    case 0:
                        mapView.MapType = MKMapType.Standard;
                        break;
                    case 1:
                        mapView.MapType = MKMapType.Satellite;
                        break;
                    case 2:
                        mapView.MapType = MKMapType.Hybrid;
                        break;
                    default:
                        break;

                }
            };
        }