Ejemplo n.º 1
0
		public GPSLocation(GPSLocation loc)
		{
			SetDefaults();

			// Copy position
			_lat = loc.Latitude;
			_lon = loc.Longitude;
			_time = loc.Time;
			_provider = loc.Provider;
			_isValid = loc.IsValid;

			// Copy Altitude only if exists
			if (loc.HasAltitude)
				_alt = loc.Altitude;
			else
				_alt = double.NaN;

			// Copy Accruracy only if exists
			if (loc.HasAccuracy) {
				_accuracy = loc.Accuracy;
				_hasAccuracy = true;
			} 

			// Copy Speed only if exists
			if (loc.HasSpeed) {
				_speed = loc.Speed;
				_hasSpeed = true;
			}

			// Copy Bearing only if exists
			if (loc.HasBearing) {
				_bearing = loc.Bearing;
				_hasBearing = true;
			}
		}
        public GPSListener(LocationManager lm, SensorManager sm, IWindowManager wm) : base()
        {
            // Get LocationManager
            _locManager    = lm;
            _windowManager = wm;

            var locationCriteria = new Criteria()
            {
                Accuracy         = global::Android.Locations.Accuracy.Fine,
                AltitudeRequired = true,
                PowerRequirement = Power.Low
            };

//			locationProvider = _locManager.GetBestProvider(locationCriteria, true);
            locationProvider = LocationManager.GpsProvider;

            if (locationProvider == null)
            {
                throw new Exception("No location provider found");
            }

            List <String> providers = _locManager.GetProviders(true) as List <String>;

            // Loop over the array backwards, and if you get an accurate location, then break out the loop
            GPSLocation loc = null;

            if (providers != null)
            {
                for (int i = providers.Count - 1; i >= 0; i--)
                {
                    loc = new GPSLocation(_locManager.GetLastKnownLocation(providers[i]));
                    if (loc != null)
                    {
                        break;
                    }
                }
            }

            // If we have an old location, than use this as first location
            if (loc != null)
            {
                _location = new GPSLocation(loc);
            }
            else
            {
                _location = new GPSLocation();
            }

            _sensorManager = sm;

            _orientationSensor   = _sensorManager.GetDefaultSensor(SensorType.Orientation);
            _accelerometerSensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
        }
Ejemplo n.º 3
0
        public GPSLocation(GPSLocation loc)
        {
            SetDefaults();

            // Copy position
            _lat      = loc.Latitude;
            _lon      = loc.Longitude;
            _time     = loc.Time;
            _provider = loc.Provider;
            _isValid  = loc.IsValid;

            // Copy Altitude only if exists
            if (loc.HasAltitude)
            {
                _alt = loc.Altitude;
            }
            else
            {
                _alt = double.NaN;
            }

            // Copy Accruracy only if exists
            if (loc.HasAccuracy)
            {
                _accuracy    = loc.Accuracy;
                _hasAccuracy = true;
            }

            // Copy Speed only if exists
            if (loc.HasSpeed)
            {
                _speed    = loc.Speed;
                _hasSpeed = true;
            }

            // Copy Bearing only if exists
            if (loc.HasBearing)
            {
                _bearing    = loc.Bearing;
                _hasBearing = true;
            }
        }
Ejemplo n.º 4
0
 public LocationChangedEventArgs(global::Android.Locations.Location loc)
 {
     _location = new GPSLocation(loc);
 }
Ejemplo n.º 5
0
 public LocationChangedEventArgs(GPSLocation loc)
 {
     _location = loc;
 }
		public GPSListener(LocationManager lm, SensorManager sm, IWindowManager wm) : base()
		{
			// Get LocationManager
			_locManager = lm;
			_windowManager = wm;

			var locationCriteria = new Criteria ()
			{
				Accuracy = global::Android.Locations.Accuracy.Fine,
				AltitudeRequired = true,
				PowerRequirement = Power.Low
			};

//			locationProvider = _locManager.GetBestProvider(locationCriteria, true);
			locationProvider = LocationManager.GpsProvider;

			if (locationProvider == null)
				throw new Exception("No location provider found");

			List<String> providers = _locManager.GetProviders(true) as List<String>;

			// Loop over the array backwards, and if you get an accurate location, then break out the loop
			GPSLocation loc = null;

			if (providers != null) {
				for (int i = providers.Count - 1; i >= 0; i--) {
					loc = new GPSLocation(_locManager.GetLastKnownLocation(providers[i]));
					if (loc != null) 
						break;
				}
			}

			// If we have an old location, than use this as first location
			if (loc != null)
			{
				_location = new GPSLocation(loc);
			} else {
				_location = new GPSLocation();
			}

			_sensorManager = sm;

			_orientationSensor = _sensorManager.GetDefaultSensor(SensorType.Orientation);
			_accelerometerSensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
		}
		/// <summary>
		/// Called when the location has changed.
		/// </summary>
		/// <param name="location">The new location, as a Location object.</param>
		public void OnLocationChanged (global::Android.Locations.Location l)
		{
			_location = new GPSLocation(l);
			if (_location != null) {
				_valid = true;
				// Check if the new location has bearing info
				if (_location.HasBearing) {
					_lastGPSAzimuth = _location.Bearing;
					SendOrientation(_lastPitch, _lastRoll);
				}
			} else {
				_valid = false;
				_location.IsValid = false;
			}

			if (LocationChanged != null)
				LocationChanged (this, new LocationChangedEventArgs (_location));
			// If Google Maps is active, than send new location
			if (mapsListener != null)
				mapsListener.OnLocationChanged(l);
		}
Ejemplo n.º 8
0
		public LocationChangedEventArgs(global::Android.Locations.Location loc)
		{
			_location = new GPSLocation(loc);
		}
Ejemplo n.º 9
0
		public LocationChangedEventArgs(GPSLocation loc)
		{
			_location = loc;
		}