예제 #1
0
        private void _onLocation(MvxGeoLocation location)
        {
            _isAvailable = true;

            if (LocationHelper.IsLocationTimestampRecent(location.Timestamp.LocalDateTime) == false)
            {
                return;
            }

            if (LocationHelper.FilterForAccuracy(location.Coordinates.Accuracy.Value, 10) == false)
            {
                return;
            }

            _currentLocation = location;

            var message = new LocationMessage(this,
                                              location.Coordinates.Longitude,
                                              location.Coordinates.Latitude,
                                              location.Coordinates.Speed,
                                              location.Coordinates.Heading,
                                              location.Coordinates.HeadingAccuracy,
                                              location.Timestamp.LocalDateTime);

            _messenger.Publish(message);
        }
        private async void Success(MvxGeoLocation location)
        {
            var address = string.Empty;

            try
            {
                var add = await _geoCoder.GetAddress(location.Coordinates.Latitude, location.Coordinates.Longitude);

                address = add.Aggregate(string.Empty, (current, s) => current + s);
#if DEBUG
                address += DateTime.Now;
#endif
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            var message = new LocationMessage(this, location.Coordinates.Latitude, location.Coordinates.Longitude)
            {
                Accuracy = location.Coordinates.Accuracy,
                Address  = address
            };
            Debug.WriteLine($"LS: {message.Lat} {message.Lng}");
            _messenger.Publish(message);
        }
예제 #3
0
        /// <summary>
        /// Called when [location].
        /// </summary>
        /// <param name="location">The location.</param>
        private void OnLocation(MvxGeoLocation location)
        {
            var message = new MvxLocationMessage(this,
                                                 location.Coordinates);

            this._messenger.Publish(message);
        }
예제 #4
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
                }
            };
        }
예제 #5
0
        private static MvxGeoLocation CreateLocation(global::Android.Locations.Location androidLocation)
        {
            var position = new MvxGeoLocation {
                Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc()
            };
            var coords = position.Coordinates;

            if (androidLocation.HasAltitude)
            {
                coords.Altitude = androidLocation.Altitude;
            }

            if (androidLocation.HasBearing)
            {
                coords.Heading = androidLocation.Bearing;
            }

            coords.Latitude  = androidLocation.Latitude;
            coords.Longitude = androidLocation.Longitude;
            if (androidLocation.HasSpeed)
            {
                coords.Speed = androidLocation.Speed;
            }
            if (androidLocation.HasAccuracy)
            {
                coords.Accuracy = androidLocation.Accuracy;
            }

            return(position);
        }
예제 #6
0
 private void OnSuccess(MvxGeoLocation obj)
 {
     _parent.RunOnUiThread(() => {
         Lat = obj.Coordinates.Latitude;
         Lng = obj.Coordinates.Longitude;
     });
 }
예제 #7
0
        private void OnLocationFound(MvxGeoLocation location)
        {
            _locationWatcher.Stop();
            _currentLocation = location;
            MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map_screen);

            mapFrag.GetMapAsync(this);
        }
예제 #8
0
 private void OnNewLocation(MvxGeoLocation location)
 {
     if (location != null && location.Coordinates != null)
     {
         Latitude  = location.Coordinates.Latitude;
         Longitude = location.Coordinates.Longitude;
     }
 }
예제 #9
0
 private void OnNewLocation(MvxGeoLocation location)
 {
     if (location != null && location.Coordinates != null)
     {
         Lat = location.Coordinates.Latitude;
         Lng = location.Coordinates.Longitude;
     }
 }
        protected override void SendLocation(MvxGeoLocation location)
        {
            // note - no need to lock here - just check then go
            if (_locationManager == null)
                return;

            base.SendLocation(location);
        }
예제 #11
0
        private void OnLocation(MvxGeoLocation location)
        {
            var message = new LocationMessage(this,
                                              location.Coordinates.Latitude,
                                              location.Coordinates.Longitude);

            _messenger.Publish(message);
        }
예제 #12
0
        protected override void SendLocation(MvxGeoLocation location)
        {
            // note - no need to lock here - just check then go
            if (_locationManager == null)
                return;

            base.SendLocation(location);
        }
예제 #13
0
 private void OnLocationUpdated(MvxGeoLocation newLocation)
 {
     Moved?.Invoke(this,
                   new LocationMovedEventArgs
     {
         Location = newLocation
     });
 }
        void locationEventHandleAction(MvxGeoLocation location)
        {
            string lat = location.Coordinates.Latitude.ToString();
            string lon = location.Coordinates.Longitude.ToString();

            CityObject       city      = new CityObject(null, null, new CityCoordinate(lat, lon));
            WeatherMainModel pageModel = new WeatherMainModel(city);

            _currentLocationPageView = new WeatherMainPageViewModel(pageModel);
        }
        public MvxGeoLocation ComputeCurrentPosition()
        {
            _lastUpdate           = DateTime.UtcNow;
            _currentLocationIndex = _currentLocationIndex + 1;

            var location = _sensorData.Locations[_currentLocationIndex];

            _currentLocation = ConvertToMvxGeoLocation(location);
            return(_currentLocation);
        }
예제 #16
0
        //LOCATIE MEEGEVEN (NODIG VOOR IN DE MESSAGE)
        private void OnLocation(MvxGeoLocation location)
        {
            //MESSAGE OPVULLEN
            var message = new LocationMessage(this,
                                              location.Coordinates.Latitude,
                                              location.Coordinates.Longitude
                                              );

            //MESSAGE PUBLISHEN
            _messenger.Publish(message);
        }
예제 #17
0
        public void onLocation(MvxGeoLocation location)
        {
            if ((DateTime.Now - _locationAcquired).TotalSeconds > 60)
            {
                this.Latitude  = location.Coordinates.Latitude;
                this.Longitude = location.Coordinates.Longitude;

                LocationAvailable = true;
                _locationAcquired = DateTime.Now;
                _messenger.Publish <LocationUpdated> (new LocationUpdated(this));
            }
        }
예제 #18
0
        private void OnSuccess(MvxGeoLocation location)
        {
            lock (_lockObject)
            {
                _latestLocation = location;
            }

            var message = new LocationMessage(this,
                                              location.Coordinates.Latitude,
                                              location.Coordinates.Longitude);

            _messenger.Publish(message);
        }
예제 #19
0
        private static MvxGeoLocation CreateLocation(CLLocation location)
        {
            var position = new MvxGeoLocation {Timestamp = location.Timestamp.ToDateTimeUtc()};
            var coords = position.Coordinates;

            coords.Altitude = location.Altitude;
            coords.Latitude = location.Coordinate.Latitude;
            coords.Longitude = location.Coordinate.Longitude;
            coords.Speed = location.Speed;
            coords.Accuracy = location.HorizontalAccuracy;
            coords.AltitudeAccuracy = location.VerticalAccuracy;

            return position;
        }
        private static MvxGeoLocation CreateLocation(GeoCoordinate coordinate, DateTimeOffset timestamp)
        {
            var position = new MvxGeoLocation {Timestamp = timestamp};
            var coords = position.Coordinates;

            coords.Altitude = coordinate.Altitude;
            coords.Latitude = coordinate.Latitude;
            coords.Longitude = coordinate.Longitude;
            coords.Speed = coordinate.Speed;
            coords.Accuracy = coordinate.HorizontalAccuracy;
            coords.AltitudeAccuracy = coordinate.VerticalAccuracy;

            return position;
        }
        private void UpdateLocation(MvxGeoLocation location)
        {
            var lat = "Unknown";
            var lng = "Unknown";

            if (location != null &&
                location.Coordinates != null)
            {
                lat = location.Coordinates.Latitude.ToString();
                lng = location.Coordinates.Longitude.ToString();
            }

            _latText.Text = lat;
            _lngText.Text = lng;
        }
예제 #22
0
        private void OnLocation(MvxGeoLocation location)
        {
            MvxMessage message = new LocationMessage(this,
                                                     location.Coordinates.Latitude,
                                                     location.Coordinates.Longitude,
                                                     string.IsNullOrEmpty(location.Coordinates.Speed.ToString()) ? 0: location.Coordinates.Speed.Value,
                                                     string.IsNullOrEmpty(location.Coordinates.Altitude.ToString()) ? 0 : location.Coordinates.Altitude.Value,
                                                     string.IsNullOrEmpty(location.Coordinates.Heading.ToString()) ? 0 : location.Coordinates.Heading.Value,
                                                     string.IsNullOrEmpty(location.Coordinates.Accuracy.ToString()) ? 0 : location.Coordinates.Accuracy.Value,
                                                     string.IsNullOrEmpty(location.Coordinates.HeadingAccuracy.ToString()) ? 0 : location.Coordinates.HeadingAccuracy.Value,
                                                     string.IsNullOrEmpty(location.Coordinates.AltitudeAccuracy.ToString()) ? 0 : location.Coordinates.AltitudeAccuracy.Value
                                                     );

            _messenger.Publish(message);
        }
예제 #23
0
        private static MvxGeoLocation CreateLocation(GeoCoordinate coordinate, DateTimeOffset timestamp)
        {
            var position = new MvxGeoLocation {
                Timestamp = timestamp
            };
            var coords = position.Coordinates;

            coords.Altitude         = coordinate.Altitude;
            coords.Latitude         = coordinate.Latitude;
            coords.Longitude        = coordinate.Longitude;
            coords.Speed            = coordinate.Speed;
            coords.Accuracy         = coordinate.HorizontalAccuracy;
            coords.AltitudeAccuracy = coordinate.VerticalAccuracy;

            return(position);
        }
예제 #24
0
        private MvxGeoLocation CreateLocation(Geocoordinate coordinate)
        {
            var position = new MvxGeoLocation {
                Timestamp = coordinate.Timestamp
            };
            var coords = position.Coordinates;

            coords.Altitude         = coordinate.Point.Position.Altitude;
            coords.Latitude         = coordinate.Point.Position.Latitude;
            coords.Longitude        = coordinate.Point.Position.Longitude;
            coords.Speed            = coordinate.Speed ?? 0.0;
            coords.Accuracy         = coordinate.Accuracy;
            coords.AltitudeAccuracy = coordinate.AltitudeAccuracy ?? double.MaxValue;

            return(position);
        }
예제 #25
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);
        }
예제 #26
0
        private MvxGeoLocation CreateLocation(Geocoordinate coordinate)
        {
            var position = new MvxGeoLocation {
                Timestamp = coordinate.Timestamp
            };
            var coords = position.Coordinates;

            // TODO - allow nullables - https://github.com/slodge/MvvmCross/issues/94
            coords.Altitude         = coordinate.Altitude ?? 0.0;
            coords.Latitude         = coordinate.Latitude;
            coords.Longitude        = coordinate.Longitude;
            coords.Speed            = coordinate.Speed ?? 0.0;
            coords.Accuracy         = coordinate.Accuracy;
            coords.AltitudeAccuracy = coordinate.AltitudeAccuracy ?? double.MaxValue;

            return(position);
        }
예제 #27
0
 private void OnLocation(MvxGeoLocation location)
 {
     //Mvx.Trace("Location Update");
     _timestamp = DateTime.Now;
     _locationMessage.Update(location.Coordinates.Latitude,
                             location.Coordinates.Longitude,
                             AppStrings.Now,
                             acc: location.Coordinates.Accuracy,
                             alt: location.Coordinates.Altitude,
                             altacc: location.Coordinates.AltitudeAccuracy,
                             hdg: location.Coordinates.Heading,
                             hdgacc: location.Coordinates.HeadingAccuracy,
                             spd: location.Coordinates.Speed);
     _messenger.Publish(_locationMessage);
     _messenger.Publish(new AlertMessage(this, AlertType.location, false));
     StartUpdateTimer();
 }
예제 #28
0
        private static MvxGeoLocation CreateLocation(CLLocation location)
        {
            var position = new MvxGeoLocation {
                Timestamp = location.Timestamp.ToDateTimeUtc()
            };
            var coords = position.Coordinates;

#warning should some of these coords fields be nullable?
            coords.Altitude         = location.Altitude;
            coords.Latitude         = location.Coordinate.Latitude;
            coords.Longitude        = location.Coordinate.Longitude;
            coords.Speed            = location.Speed;
            coords.Accuracy         = location.HorizontalAccuracy;
            coords.AltitudeAccuracy = location.VerticalAccuracy;

            return(position);
        }
예제 #29
0
        private static MvxGeoLocation CreateLocation(global::Android.Locations.Location androidLocation)
        {
            var position = new MvxGeoLocation {
                Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc()
            };
            var coords = position.Coordinates;

#warning should some of these coords fields be nullable?
            if (androidLocation.HasAltitude)
            {
                coords.Altitude = androidLocation.Altitude;
            }

#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
#warning MONODROID BUG WORKAROUND!
            var testString = androidLocation.ToString();
            coords.Latitude  = HackReadValue(testString, "mLatitude=");
            coords.Longitude = HackReadValue(testString, "mLongitude=");

            return(position);

            /*
             * coords.Latitude = androidLocation.Latitude;
             * coords.Longitude = androidLocation.Longitude;
             * if (androidLocation.HasSpeed)
             *  coords.Speed = androidLocation.Speed;
             * if (androidLocation.HasAccuracy)
             * {
             *  coords.Accuracy = androidLocation.Accuracy;
             * }
             *
             #warning what to do with coords.AltitudeAccuracy ?S
             * //coords.AltitudeAccuracy = androidLocation.Accuracy;
             *
             * return position;
             */
        }
예제 #30
0
        private MvxGeoLocation CreateLocation(GeoCoordinate coordinate)
        {
            var position = new MvxGeoLocation {
                Timestamp = DateTime.Now
            };
            var coords = position.Coordinates;

            // TODO - Not sure how to deal with zero values - as we can't distinguish between null and zero values...
            coords.Altitude         = coordinate.Altitude;
            coords.Latitude         = coordinate.Latitude;
            coords.Longitude        = coordinate.Longitude;
            coords.Speed            = coordinate.Speed;
            coords.Accuracy         = coordinate.HorizontalAccuracy;
            coords.AltitudeAccuracy = coordinate.VerticalAccuracy;

            _lastKnownPosition = position;

            return(position);
        }
예제 #31
0
        private static MvxGeoLocation CreateLocation(CLLocation location, CLHeading heading)
        {
            var position = new MvxGeoLocation { Timestamp = location.Timestamp.ToDateTimeUtc() };
            var coords = position.Coordinates;

            coords.Altitude = location.Altitude;
            coords.Latitude = location.Coordinate.Latitude;
            coords.Longitude = location.Coordinate.Longitude;
            coords.Speed = location.Speed;
            coords.Accuracy = location.HorizontalAccuracy;
            coords.AltitudeAccuracy = location.VerticalAccuracy;
            if (heading != null)
            {
                coords.Heading = heading.TrueHeading;
                coords.HeadingAccuracy = heading.HeadingAccuracy;
            }

            return position;
        }
        private static MvxGeoLocation CreateLocation(CLLocation location, CLHeading heading)
        {
            var position = new MvxGeoLocation { Timestamp = location.Timestamp.ToDateTimeUtc() };
            var coords = position.Coordinates;

            coords.Altitude = location.Altitude;
            coords.Latitude = location.Coordinate.Latitude;
            coords.Longitude = location.Coordinate.Longitude;
            coords.Speed = location.Speed;
            coords.Accuracy = location.HorizontalAccuracy;
            coords.AltitudeAccuracy = location.VerticalAccuracy;
            if (heading != null)
            {
                coords.Heading = heading.TrueHeading;
                coords.HeadingAccuracy = heading.HeadingAccuracy;
            }

            return position;
        }
        private static MvxGeoLocation CreateLocation(global::Android.Locations.Location androidLocation)
        {
            var position = new MvxGeoLocation {Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc()};
            var coords = position.Coordinates;

            if (androidLocation.HasAltitude)
                coords.Altitude = androidLocation.Altitude;

			if (androidLocation.HasBearing)
				coords.Heading = androidLocation.Bearing;

            coords.Latitude = androidLocation.Latitude;
            coords.Longitude = androidLocation.Longitude;
            if (androidLocation.HasSpeed)
                coords.Speed = androidLocation.Speed;
            if (androidLocation.HasAccuracy)
            {
                coords.Accuracy = androidLocation.Accuracy;
            }

            return position;
        }
 private void OnLocationUpdated(MvxGeoLocation location)
 {
     Location = string.Format("({0:##.#}, {1:##.#})", location.Coordinates.Latitude, location.Coordinates.Longitude);
 }
예제 #35
0
        private void UpdateLocation(MvxGeoLocation location)
        {
            var lat = "Unknown";
            var lng = "Unknown";

            if (location != null
                && location.Coordinates != null)
            {
                lat = location.Coordinates.Latitude.ToString();
                lng = location.Coordinates.Longitude.ToString();
            }

            _latText.Text = lat;
            _lngText.Text = lng;
        }
        private MvxGeoLocation CreateLocation(GeoCoordinate coordinate)
        {
            var position = new MvxGeoLocation { Timestamp = DateTime.Now };
            var coords = position.Coordinates;

            // TODO - Not sure how to deal with zero values - as we can't distinguish between null and zero values...
            coords.Altitude = coordinate.Altitude;
            coords.Latitude = coordinate.Latitude;
            coords.Longitude = coordinate.Longitude;
            coords.Speed = coordinate.Speed;
            coords.Accuracy = coordinate.HorizontalAccuracy;
            coords.AltitudeAccuracy = coordinate.VerticalAccuracy;

            _lastKnownPosition = position;

            return position;
        }
예제 #37
0
 private void OnLocation(MvxGeoLocation location)
 {
     Location = location;
 }
        private MvxGeoLocation CreateLocation(Geocoordinate coordinate)
        {
            var position = new MvxGeoLocation { Timestamp = coordinate.Timestamp };
            var coords = position.Coordinates;

            // TODO - allow nullables - https://github.com/slodge/MvvmCross/issues/94
            coords.Altitude = coordinate.Altitude ?? 0.0;
            coords.Latitude = coordinate.Latitude;
            coords.Longitude = coordinate.Longitude;
            coords.Speed = coordinate.Speed ?? 0.0;
            coords.Accuracy = coordinate.Accuracy;
            coords.AltitudeAccuracy = coordinate.AltitudeAccuracy ?? double.MaxValue;

            return position;
        }
예제 #39
0
 private void OnLocation(MvxGeoLocation obj)
 {
     Lat  = obj.Coordinates.Latitude;
     Long = obj.Coordinates.Longitude;
 }
        private static MvxGeoLocation CreateLocation(global::Android.Locations.Location androidLocation)
        {
            var position = new MvxGeoLocation {Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc()};
            var coords = position.Coordinates;

            if (androidLocation.HasAltitude)
                coords.Altitude = androidLocation.Altitude;

            // note that we use a HackReadValue method from a string here 
            // - as MONODROID didn't seem to be correctly returning the Latitude and Longitude values
            var testString = androidLocation.ToString();
            coords.Latitude = HackReadValue(testString, "mLatitude=");
            coords.Longitude = HackReadValue(testString, "mLongitude=");

            return position;
            /*
            coords.Latitude = androidLocation.Latitude;
            coords.Longitude = androidLocation.Longitude;
            if (androidLocation.HasSpeed)
                coords.Speed = androidLocation.Speed;
            if (androidLocation.HasAccuracy)
            {
                coords.Accuracy = androidLocation.Accuracy;
            }

#warning what to do with coords.AltitudeAccuracy ?S
            //coords.AltitudeAccuracy = androidLocation.Accuracy;

            return position;
             */
        }
예제 #41
0
 private void OnLocation(MvxGeoLocation location)
 {
     RunOnUiThread(() => UpdateLocation(location));
 }
 private void OnLocation(MvxGeoLocation location)
 {
     Location = location;
 }
 protected virtual void SendLocation(MvxGeoLocation location)
 {
     var callback = _locationCallback;
     if (callback != null)
         callback(location);            
 }