コード例 #1
0
 public void Start(bool fine = false)
 {
     if (isStarted)
     {
         return;
     }
     isStarted = true;
     if (fine)
     {
         watcher.Start(new MvxLocationOptions
         {
             Accuracy             = MvxLocationAccuracy.Fine,
             TrackingMode         = MvxLocationTrackingMode.Foreground,
             TimeBetweenUpdates   = TimeSpan.FromSeconds(5),
             MovementThresholdInM = 0
         }, OnLocation, OnError);
     }
     else
     {
         watcher.Start(new MvxLocationOptions
         {
             Accuracy             = MvxLocationAccuracy.Coarse,
             TrackingMode         = MvxLocationTrackingMode.Foreground,
             TimeBetweenUpdates   = TimeSpan.FromSeconds(30),
             MovementThresholdInM = 0
         }, OnLocation, OnError);
     }
 }
コード例 #2
0
        public void Init()
        {
            if (!locationWatcher.Started)
            {
                locationWatcher.Start(
                    new MvxLocationOptions {
                    Accuracy = MvxLocationAccuracy.Coarse
                },
                    loc =>
                {
                    UserLocation           = loc;
                    const double tolerance = 0.001;
                    if (Math.Abs(loc.Coordinates.Latitude) > tolerance &&
                        Math.Abs(loc.Coordinates.Longitude) > tolerance)
                    {
                        locationWatcher.Stop();
                    }
                },
                    error => { });
            }

            // defaults
            userAge      = 0;
            userId       = string.Empty;
            userGender   = Gender.Unknown;
            userLocation = new MvxGeoLocation
            {
                Coordinates = new MvxCoordinates
                {
                    Latitude  = 0,
                    Longitude = 0,
                    Accuracy  = 0
                }
            };
        }
コード例 #3
0
 public void StartGetCurrentLocation(MvxLocationOptions options, Action <MvxGeoLocation> locationHandler, Action <MvxLocationError> errorHandler)
 {
     if (_locationWatcher != null)
     {
         _locationWatcher.Start(options ?? _locationOptions, locationHandler, errorHandler);
     }
 }
コード例 #4
0
        public LocationService(IMvxLocationWatcher watcher)
        {
            StatusMessage = "Current location is being resolved...";

            _watcher = watcher;
            _watcher.Start(new MvxLocationOptions() { TimeBetweenUpdates = new TimeSpan(0, 0, 1), Accuracy = MvxLocationAccuracy.Fine }, OnLocation, OnError);
        }
コード例 #5
0
ファイル: GpsService.cs プロジェクト: alexschott/mwf
 public GpsService(IMvxLocationWatcher locationWatcher)
 {
     _locationWatcher = locationWatcher;
     if (!_locationWatcher.Started)
     {
         _locationWatcher.Start(new MvxLocationOptions(), OnSuccess, OnError);
     }
 }
コード例 #6
0
ファイル: LocationService.cs プロジェクト: knarte/TestingApp
 public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
 {
     _watcher   = watcher;
     _messenger = messenger;
     _watcher.Start(new MvxLocationOptions()
     {
         Accuracy = MvxLocationAccuracy.Fine, TrackingMode = MvxLocationTrackingMode.Background
     }, OnLocation, OnError);
 }
コード例 #7
0
        //Init
        //

        public WeatherPagedViewModel(WeatherPageModel model, IMvxLocationWatcher watcher, IMvxMessenger massager)
        {
            _massager = massager;
            _token    = _massager.Subscribe <CitiesMassage>(OnUpdateCities);
            _watcher  = watcher;
            _watcher.Start(new MvxLocationOptions(), locationEventHandleAction, errorEventHandleAction);
            _model = model;
            this.InitViewModels();
        }
コード例 #8
0
        public LocationService(IMvxLocationWatcher watcher)
        {
            StatusMessage = "Current location is being resolved...";

            _watcher = watcher;
            _watcher.Start(new MvxLocationOptions()
            {
                TimeBetweenUpdates = new TimeSpan(0, 0, 1), Accuracy = MvxLocationAccuracy.Fine
            }, OnLocation, OnError);
        }
コード例 #9
0
 public void StartWatching()
 {
     if (!_watcher.Started)
     {
         _watcher.Start(new MvxLocationOptions {
             TimeBetweenUpdates = Constants.TimeBetweenUpdates, TrackingMode = MvxLocationTrackingMode.Background
         }, Success, Error);
     }
     Debug.WriteLine("Start watching");
 }
コード例 #10
0
        public FirstViewModel(IMvxLocationWatcher locationWatcher)
        {
            this.locationWatcher = locationWatcher;

            Permission = "not specified";
            Location   = "zero";

            locationWatcher.OnPermissionChanged += OnPermissionChanged;
            locationWatcher.Start(new MvxLocationOptions(), OnLocationUpdated, OnLocationError);
        }
コード例 #11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.map_screen);

            _locationWatcher = Mvx.Resolve <IMvxLocationWatcher>();
            var options = new MvxLocationOptions();

            _locationWatcher.Start(options, OnLocationFound, OnLocationNotFound);
        }
コード例 #12
0
        //private readonly MvxMessenger _messenger;

        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher   = watcher;
            _messenger = messenger;
            var options = new MvxLocationOptions
            {
                MovementThresholdInM = 2500
            };

            _watcher.Start(options, OnLocation, OnError);
        }
コード例 #13
0
        public async void Start()
        {
            await EnsurePermissionExists();

            _watcher.Start(new MvxLocationOptions {
                Accuracy             = MvxLocationAccuracy.Fine,
                TimeBetweenUpdates   = TimeSpan.FromSeconds(1),
                MovementThresholdInM = 1,
                TrackingMode         = MvxLocationTrackingMode.Foreground
            }, OnLocation, OnError);
        }
コード例 #14
0
        public FirstViewModel(IMvxLocationWatcher locationWatcher)
        {
            _locationWatcher = locationWatcher;

            _locationWatcher.Start(new MvxLocationOptions {
                Accuracy = MvxLocationAccuracy.Fine
            }, OnLocation, OnError);
            _lat = _locationWatcher.CurrentLocation.Coordinates.Latitude;
            _lng = _locationWatcher.CurrentLocation.Coordinates.Longitude;
            _locationWatcher.Stop();
            System.Diagnostics.Debug.WriteLine($"Lat: {Lat} Lng: {Lng}");
        }
コード例 #15
0
 public void Start()
 {
     if (_watcher.Started == false)
     {
         _watcher.OnPermissionChanged += _permissionChanged;
         _watcher.Start(new MvxLocationOptions()
         {
             Accuracy     = MvxLocationAccuracy.Fine,
             TrackingMode = MvxLocationTrackingMode.Foreground,
         }, _onLocation, _onError);
     }
 }
コード例 #16
0
ファイル: LocationService.cs プロジェクト: Xciles/Inferno
        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher   = watcher;
            _messenger = messenger;
            var options = new MvxLocationOptions()
            {
                Accuracy             = MvxLocationAccuracy.Fine,
                MovementThresholdInM = 5,
                TrackingMode         = MvxLocationTrackingMode.Foreground
            };

            _watcher.Start(options, OnLocation, OnError);
            OnLocation(_watcher.CurrentLocation);
        }
コード例 #17
0
 public FirstViewModel(ICustomerService customerService, IMvxLocationWatcher watcher)
 {
     _customerService = customerService;
     _watcher = watcher;
     if (_watcher != null)
     {
         if (!_watcher.Started)
             _watcher.Start(new MvxLocationOptions(), OnLocationFound, OnError);
     }
     if (string.IsNullOrWhiteSpace(Lat) || string.IsNullOrWhiteSpace(Lon))
     {
         Lat = "12.950545";
         Lon = "77.642149";
     }
 }
コード例 #18
0
ファイル: LocationService.cs プロジェクト: klzig/MapX
        public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
        {
            _watcher         = watcher;
            _messenger       = messenger;
            _locationMessage = new LocationMessage(this);
            _updateLoc_token = _messenger.Subscribe <UpdateLocMessage>(OnUpdateLocMessage);

            var options = new MvxLocationOptions
            {
                Accuracy           = MvxLocationAccuracy.Fine,
                TimeBetweenUpdates = TimeSpan.FromSeconds(2),
                TrackingMode       = MvxLocationTrackingMode.Foreground
            };

            _watcher.Start(options, OnLocation, OnError);
        }
コード例 #19
0
        public Task <MvxGeoLocation> GetLocation(CancellationTokenSource tokenSource = null)
        {
            var tcs = new TaskCompletionSource <MvxGeoLocation>();

            StopLocationWatcher();
            _locationWatcher.Start(new MvxLocationOptions()
            {
                Accuracy     = MvxLocationAccuracy.Coarse,
                TrackingMode = MvxLocationTrackingMode.Background
            }, location =>
            {
                tcs.TrySetResult(location);
                _locationWatcher.Stop();
            },
                                   error =>
            {
                tcs.TrySetResult(null);
            });

            Task.Run(async() =>
            {
                if (tokenSource != null)
                {
                    await Task.Delay(60000, tokenSource.Token);
                }
                else
                {
                    await Task.Delay(60000);
                }

                if (!tcs.Task.IsCompleted)
                {
                    MvxGeoLocation currLocation = null;
                    try
                    {
                        currLocation = _locationWatcher.CurrentLocation;
                    }
                    catch
                    {
                    }

                    tcs.TrySetResult(currLocation);
                }
            });

            return(tcs.Task);
        }
コード例 #20
0
        private Task <Location> CalculatePositionInternalAsync()
        {
            var tcs = new TaskCompletionSource <Location>();

            _watcher.Start(
                new MvxLocationOptions
            {
                Accuracy             = MvxLocationAccuracy.Fine,
                MovementThresholdInM = 150,
                TimeBetweenUpdates   = new TimeSpan(0, 0, 0, 15)
            },
                location => tcs.TrySetResult(new Location {
                Latitude = location.Coordinates.Latitude, Longitude = location.Coordinates.Longitude
            }),
                error => tcs.TrySetException(new Exception(error.Code.ToString())));

            return(tcs.Task);
        }
コード例 #21
0
ファイル: LocationService.cs プロジェクト: Xciles/Inferno
 public MvxGeoLocation LastLocation()
 {
     if (_watcher.Started)
     {
         return(_watcher.CurrentLocation);
     }
     else
     {
         var options = new MvxLocationOptions()
         {
             Accuracy             = MvxLocationAccuracy.Fine,
             MovementThresholdInM = 5,
             TrackingMode         = MvxLocationTrackingMode.Foreground
         };
         _watcher.Start(options, OnLocation, OnError);
         return(_watcher.CurrentLocation);
     }
 }
コード例 #22
0
        public StartViewModel(IMvxNavigationService navigationService, IMvxLocationWatcher watcher)
        {
            _navigation = navigationService;
            _watcher    = watcher;
            _watcher.Start(new MvxLocationOptions(), OnLocation, OnError);
            SearchCmd = new MvxCommand(() =>
            {
                _navigation.Navigate <PostsViewModel, SearchModel>(new SearchModel {
                    KeyWord = this.KeyWord, StartDate = this.StartDate, EndDate = this.EndDate
                });
            });

            EndDate = DateTime.Now.ToShortDateString();

            SetLocationCmd = new MvxCommand(() =>
            {
                // Long = _watcher.CurrentLocation.Coordinates.Longitude;
                // Lat = _watcher.CurrentLocation.Coordinates.Latitude;
                Location = "Lublin";
            });
        }
コード例 #23
0
        private void StartWatcher()
        {
            Console.WriteLine("StartWatcher");

            _dispatcher.ExecuteOnMainThreadAsync(() =>
            {
                if (_locationWatcher.Started)
                {
                    Console.WriteLine("Watcher already started!");
                    return;
                }

                _locationWatcher.Start(new MvxLocationOptions()
                {
                    Accuracy = MvxLocationAccuracy.Coarse
                },
                                       location =>
                {
                    _locationWatcher.Stop();

                    OnSuccess(new MvxCoordinates()
                    {
                        Latitude  = location.Coordinates.Latitude,
                        Longitude = location.Coordinates.Longitude
                    });
                },
                                       error =>
                {
                    _locationWatcher.Stop();
                    Console.WriteLine(error.Code);
                    OnError(new Exception(error.Code.ToString()));
                });

                Task.Delay(_timeOut).ContinueWith(_ => OnTimeout());
            });
        }
コード例 #24
0
 void InitializeLocation(MvxLocationOptions locationOptions)
 {
     _location.Start(locationOptions, onLocation, onError);
 }
コード例 #25
0
 public LocationService(IMvxLocationWatcher watcher, IMvxMessenger messenger)
 {
     _watcher   = watcher;
     _messenger = messenger;
     _watcher.Start(new MvxLocationOptions(), OnLocation, OnError);
 }
コード例 #26
0
 public Child3ViewModel(IMvxLocationWatcher watcher)
 {
     _watcher = watcher;
     _watcher.Start(new MvxLocationOptions(), OnFix, OnError);
     LocationEntity = new ObservableCollection <LocationEntity>(Parameters.LocationEntityManager.GetItems().ToList());
 }
コード例 #27
0
 public Child3ViewModel(IMvxLocationWatcher watcher)
 {
     _watcher = watcher;
     _watcher.Start(new MvxLocationOptions(), OnFix, OnError);
 }
コード例 #28
0
 public FirstViewModel(IMvxLocationWatcher watcher)
 {
     _watcher = watcher;
     _watcher.Start(new MvxLocationOptions(), OnLocation, OnError);
 }
コード例 #29
0
 public void StartLocationWatcher(MvxLocationOptions options)
 {
     _watcher.Start(options, OnLocation, OnError);
 }
コード例 #30
0
 public FirstViewModel(IMvxLocationWatcher watcher)
 {
     _watcher = watcher;
     _watcher.Start(new MvxLocationOptions(), OnLocation, OnError);
 }