예제 #1
0
        public App()
        {
            App.Self = this;

            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;

            var position = locator.GetPositionAsync(timeoutMilliseconds: 10000).ContinueWith((t) =>
           {
               if (t.IsCompleted)
               {
                   if (MyPosition == null)
                       MyPosition = new MyLatLong();
                   MyPosition.Latitude = t.Result.Latitude;
                   MyPosition.Longitude = t.Result.Longitude;
               }
           }).ConfigureAwait(true);

            PositionChanged += (object sender, PositionEventArgs e) =>
            {
                MyPosition.Latitude = e.Position.Latitude;
                MyPosition.Longitude = e.Position.Longitude;
                MessagingCenter.Send<App>(this, "LocChange");
            };

            PositionError += (object sender, PositionErrorEventArgs e) =>
            {
                MessagingCenter.Send<App, string>(this, "LocError", e.Error.ToString());
            };

            CrossGeolocator.Current.StartListeningAsync(1, 50, false);

            MainPage = new NavigationPage(new MappingPage());
        }
예제 #2
0
        public App()
        {
            App.Self = this;

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var position = locator.GetPositionAsync(timeoutMilliseconds: 10000).ContinueWith((t) =>
            {
                if (t.IsCompleted)
                {
                    if (MyPosition == null)
                    {
                        MyPosition = new MyLatLong();
                    }
                    MyPosition.Latitude  = t.Result.Latitude;
                    MyPosition.Longitude = t.Result.Longitude;
                }
            }).ConfigureAwait(true);

            PositionChanged += (object sender, PositionEventArgs e) =>
            {
                MyPosition.Latitude  = e.Position.Latitude;
                MyPosition.Longitude = e.Position.Longitude;
                MessagingCenter.Send <App>(this, "LocChange");
            };

            PositionError += (object sender, PositionErrorEventArgs e) =>
            {
                MessagingCenter.Send <App, string>(this, "LocError", e.Error.ToString());
            };

            CrossGeolocator.Current.StartListeningAsync(1, 50, false);

            MainPage = new NavigationPage(new MappingPage());
        }