Exemplo n.º 1
0
        async Task GetPosition()
        {
            // Inicia o Acelelometro
            var device = Resolver.Resolve <IDevice>();

            Debug.WriteLine(device.FirmwareVersion);


            this.geolocator = DependencyService.Get <IGeolocator> ();
            //geolocator.PositionError += OnPositionError;
            //geolocator.PositionChanged += OnPositionChanged;

            if (!geolocator.IsListening)
            {
                geolocator.StartListening(minTime: 1000, minDistance: 0);
            }

            var position = await geolocator.GetPositionAsync(timeout : 10000);

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

            Debug.WriteLine(message);

            device.Accelerometer.ReadingAvailable += getEixos;
        }
Exemplo n.º 2
0
        private async Task <XLabs.Platform.Services.Geolocation.Position> GetCurrentPosition()
        {
            IGeolocator geolocator = Resolver.Resolve <IGeolocator>();

            XLabs.Platform.Services.Geolocation.Position result = null;

            if (geolocator.IsGeolocationEnabled)
            {
                try {
                    if (!geolocator.IsListening)
                    {
                        geolocator.StartListening(1000, 1000);
                    }

                    var task = await geolocator.GetPositionAsync(10000);

                    result = task;

                    System.Diagnostics.Debug.WriteLine("[GetPosition] Lat. : {0} / Long. : {1}", result.Latitude.ToString("N4"), result.Longitude.ToString("N4"));
                }
                catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine("Error : {0}", e);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 private void LocationClicked(View v)
 {
     locationEntry.Text = "";
     LocationFilter     = null;
     locator.StopListening();
     locator.StartListening(0, 0);
 }
Exemplo n.º 4
0
        public SearchFilersPage()
        {
            Utils.SetupPage(this);
            BuildLayout();

            locator = Xamarin.Forms.DependencyService.Get <IGeolocator>();
            locator.PositionChanged += (o, arg) =>
            {
                locator.StopListening();
                if (arg.Position != null)
                {
                    LocationFilter = new LocationFilter()
                    {
                        Lat    = arg.Position.Latitude,
                        Lon    = arg.Position.Longitude,
                        Radius = RADIUS
                    };
                    LocationAddress = "Current location";
                }
            };
            locator.PositionError += (o, arg) =>
            {
                locator.StopListening();
            };
            locator.StopListening();
            locator.StartListening(0, 0);
        }
Exemplo n.º 5
0
        public App()
        {
            IGeolocator locator = DependencyService.Get <IGeolocator>();

            locator.DesiredAccuracy         = 50;
            locator.AllowsBackgroundUpdates = true;
            locator.StartListening(1, 1, true);
            locator.PositionChanged += LocatorPositionChanged;

            Button button = new Button
            {
                Text = "Get Position!"
            };

            button.Clicked += async(sender, e) => await GetCurrentLocationAsync(locator);

            gpsLabel = new Label
            {
                Text = "GPS Coordinates"
            };

            // The root page of your application
            MainPage = new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        gpsLabel,
                        button
                    }
                }
            };
        }
Exemplo n.º 6
0
 public void StartListening()
 {
     if (m_Locator != null &&
         !m_Locator.IsListening)
     {
         m_Locator.PositionChanged += LocationManager_PositionChanged;
         m_Locator.StartListening(10, 10);
     }
 }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            locator.StartListening(50, 1);

            locator.PositionChanged += async(object sender, PositionEventArgs e) => {
                var position = await locator.GetPositionAsync(timeout : 10000);

                longitude.Text = "Longitude: " + position.Longitude.ToString();
                latitude.Text  = "Latitude: " + position.Longitude.ToString();
            };
        }
Exemplo n.º 8
0
        /// <summary>
        /// Method that handles the ToggleGps message
        /// </summary>
        public void HandleToggleGpsMessage()
        {
            if (_locator == null)
            {
                CountDown();
                SetupGps();
                //_locator.StartListening(Definitions.MinInterval, Definitions.Accuracy, false);
                _isListening = true;
                return;
            }

            _pause = !_pause;
            if (_pause)
            {
                SetAccuracy();
                var test = _locator.IsGeolocationAvailable;
                if (!test)
                {
                    GpsNotAvailable();
                }
                else
                {
                    if (!_firstRun)
                    {
                        _doTestCheck = true;
                    }

                    CountDown();
                    _locator.StartListening(Definitions.MinInterval, Definitions.Accuracy, false);
                }
            }
            else
            {
                SetAccuracy();
                _locator.StopListening();
                _trackChanges   = false;
                Signal          = false;
                _pauseLatitude  = _positionLatitude;
                _pauseLongitude = _positionLongitude;
                if (Definitions.Route.GPSCoordinates.Count > 0)
                {
                    Definitions.Route.GPSCoordinates.Last().IsViaPoint = "true";
                }
            }
        }
Exemplo n.º 9
0
        private async void GetPosition()
        {
            try
            {
                var position = await _geolocator.GetPositionAsync(10000);

                UserPosition = position == null
                    ? new Position(0, 0)
                    : new Position(position.Latitude, position.Longitude);
                _geolocator.PositionChanged       +=
                    (sender, args) => UserPosition = new Position(args.Position.Latitude, args.Position.Longitude);
                _geolocator.StartListening(10000, 5);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
Exemplo n.º 10
0
 private void ListenToPosition(bool listening)
 {
     if (_location.IsListening)
     {
         try
         {
             _location.StopListening();
         }
         catch { }
     }
     if (listening)
     {
         _location.PositionChanged += LocationService_PositionChanged;
         try
         {
             _location.StartListening(10000, 30);
         }
         catch { }
     }
 }
Exemplo n.º 11
0
 private void AutoPositionSwitch_Toggled(object sender, ToggledEventArgs e)
 {
     if (e.Value)
     {
         if (!_location.IsListening)
         {
             try
             {
                 _location.StartListening(10000, 30);
             }
             catch { }
         }
     }
     else
     {
         try
         {
             _location.StopListening();
         }
         catch { }
     }
 }
Exemplo n.º 12
0
        void OnAppReady()
        {
            // This code CAN be placed to shared part,
            // the reason we didn't do that here is
            // strange bug,

            app.Label.Text = "Waiting for location...";

            geolocator = DependencyService.Get <IGeolocator>();

            geolocator.PositionChanged += (sender, e) => {
                app.Label.Text = String.Format("Lat: {0}, Lng: {1}",
                                               e.Position.Latitude, e.Position.Longitude);
            };

            geolocator.PositionError += (sender, e) => {
                app.Label.Text = "Update location error!";
            };

            if (geolocator.IsGeolocationAvailable || geolocator.IsGeolocationEnabled)
            {
                geolocator.StartListening(10, 200);
            }
        }
Exemplo n.º 13
0
        private async void LoadMap()
        {
            //map.Pins.Clear();
            //map.RouteCoordinates.Clear();
            //map.ShapeCoordinates.Clear();
            //map.IsVisible = true;

            //map.MapPositionOption = CurrentRecordEdit.Position;
            //switch (CurrentRecordEdit.Position)
            //{
            //	case PositionInfo.PositionOption.Pin:
            //		map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(CurrentRecordEdit.Latitude, CurrentRecordEdit.Longitude), new Distance(100)));
            //		UpdatePin();
            //		break;
            //	case PositionInfo.PositionOption.Line:
            //		foreach (var position in CurrentRecordEdit.PositionList)
            //		{
            //			map.RouteCoordinates.Add(new Position(position.Latitude, position.Longitude));
            //		}
            //		map.MoveToRegion(MapSpan.FromCenterAndRadius(GetCenterOfPositions(CurrentRecordEdit.PositionList), new Distance(GetDistanceFromCenter(CurrentRecordEdit.PositionList))));
            //		break;
            //	case PositionInfo.PositionOption.Area:
            //		foreach (var position in CurrentRecordEdit.PositionList)
            //		{
            //			map.ShapeCoordinates.Add(new Position(position.Latitude, position.Longitude));
            //		}
            //		map.MoveToRegion(MapSpan.FromCenterAndRadius(GetCenterOfPositions(CurrentRecordEdit.PositionList), new Distance(GetDistanceFromCenter(CurrentRecordEdit.PositionList))));
            //		break;
            //	default:
            //		break;
            //}

            MapSpan span = MapSpan.FromCenterAndRadius(new Position(RecordEditViewModel.Latitude, RecordEditViewModel.Longitude), new Distance(75000));

            map.MoveToRegion(span);

            try
            {
                var statusLocation = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                if (statusLocation != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                    {
                        await Application.Current.MainPage.DisplayAlert("Benötige Standort-Berechtigung", "Zum automatischen Feststellen des Fundorts wird die Standort-Berechtigung benötigt.", "Okay");
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });

                    statusLocation = results[Permission.Location];
                }
                if (statusLocation == PermissionStatus.Granted)
                {
                    _location = DependencyService.Get <IGeolocator>();
                }
                else if (statusLocation != PermissionStatus.Unknown)
                {
                    await Application.Current.MainPage.DisplayAlert("Berechtigung verweigert", "Ohne Berechtigung kann der Standort nicht automatisch festgestellt werden.", "Okay");
                }
            }
            catch
            {
            }

            _location = DependencyService.Get <IGeolocator>();

            // LoadMap();

            if (!RecordEditViewModel.ExistingRecord && _location != null && _location.IsGeolocationAvailable && _location.IsGeolocationEnabled)
            {
                try
                {
                    _location.PositionChanged += LocationService_PositionChanged;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                if (_location.IsListening)
                {
                    try
                    {
                        _location.StopListening();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                try
                {
                    _location.StartListening(10000, 30);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                RecordEditViewModel.AutoPosition = true;
                AutoPositionSwitch.IsEnabled     = true;
            }
            else
            {
                RecordEditViewModel.AutoPosition = false;
                AutoPositionSwitch.IsEnabled     = false;
            }

            if (Device.RuntimePlatform == Device.Android)
            {
                MapHolder.Scrolled += OnScrolled;
            }
        }
		async Task GetPosition ()
		{
			// Inicia o Acelelometro
			var device = Resolver.Resolve<IDevice>();
			Debug.WriteLine (device.FirmwareVersion);


			this.geolocator = DependencyService.Get<IGeolocator> ();
			//geolocator.PositionError += OnPositionError;
			//geolocator.PositionChanged += OnPositionChanged;

			if (!geolocator.IsListening)
				geolocator.StartListening(minTime: 1000, minDistance: 0);

			var position = await geolocator.GetPositionAsync (timeout: 10000);

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

			Debug.WriteLine (message);

			device.Accelerometer.ReadingAvailable += getEixos;


		}