public async Task OnReading(IGpsReading reading) { var e = new GpsEvent { Id = Guid.NewGuid().ToString(), DateCreated = DateTimeOffset.UtcNow, Latitude = reading.Position.Latitude, Longitude = reading.Position.Longitude, Heading = reading.Heading, HeadingAccuracy = reading.HeadingAccuracy, Speed = reading.Speed, PositionAccuracy = reading.PositionAccuracy }; await this.repository.Set(e.Id, e); this.BatchSize++; var job = await this.jobManager.GetJob(Constants.GpsJobIdentifier); var config = job.GetSyncConfig(); if (this.BatchSize >= config.BatchSize) { this.BatchSize = 0; Console.WriteLine("GPS Location Sync batch size reached, will attempt to sync"); if (this.jobManager.IsRunning) { await this.jobManager.RunJobAsTask(Constants.GpsJobIdentifier); } } }
protected override void OnResume() { try { this.logDebug(LogLevel.Verbose, "Entering OnResume"); lastGpsEvent_debug = GpsEvent.Stopped; base.OnResume(); logDebug(LogLevel.Verbose, "RESUMED"); LocationManager lm = (LocationManager)GetSystemService(Context.LocationService); lm.AddGpsStatusListener(this); if (updateReadiness()) // gps could be switched meanwhile { showAlarm("running", Android.Graphics.Color.GreenYellow); ServiceReceiver.SendInfoRequest(this); } this.logDebug(LogLevel.Verbose, "Done OnResume"); } catch (Exception ex) { this.logDebug(LogLevel.Error, "OnResume " + ex.ToString()); } }
public void OnGpsStatusChanged(GpsEvent e) { if (e == GpsEvent.FirstFix) { //We have fix for sure LocationSensorStatus = LocationSensorStatus.Working; } else if (e == GpsEvent.SatelliteStatus) { //Don't really care anymore } }
public void OnGpsStatusChanged([GeneratedEnum] GpsEvent e) { if (e == GpsEvent.Started || e == GpsEvent.Stopped) { logDebug(LogLevel.Verbose, "MA gps changed to " + e.ToString()); updateReadiness(); } else if (e != lastGpsEvent_debug) // prevents polluting log with SatelliteStatus value { logDebug(LogLevel.Verbose, $"MA minor status gps changed to {e}"); this.lastGpsEvent_debug = e; } }
public void OnGpsStatusChanged(GpsEvent e) { LocationStatus gpsStatus = LocationStatus.Started; if (e == GpsEvent.Stopped) { gpsStatus = LocationStatus.Stopped; } var handler = LocationStatusChanged; handler?.Invoke(this, new LocationStatusChangedEventArgs() { Status = gpsStatus }); }
public void OnGpsStatusChanged(GpsEvent e) { int satellitesCount = 0; var gpsStatus = _gpsLocationManager.GetGpsStatus(null); var iterator = gpsStatus.Satellites.Iterator(); while (iterator.HasNext) { var satelite = (GpsSatellite)iterator.Next(); if (satelite.UsedInFix()) { satellitesCount++; } } _satellitesCount = satellitesCount; }
public void OnGpsStatusChanged(GpsEvent e) { GpsStatus gpsStatus = locationManager.GetGpsStatus(null); if (gpsStatus != null) { IIterable satellites = gpsStatus.Satellites; IIterator sat = satellites.Iterator(); string lSatellites = null; int i = 0; while (sat.HasNext) { GpsSatellite satellite = sat.Next().JavaCast <GpsSatellite>(); Debug.WriteLine(satellite.Prn); } } }
public void OnGpsStatusChanged(GpsEvent e) { int satellitesInView = 0; int satellitesInUse = 0; var gpsStatus = _gpsLocationManager.GetGpsStatus(null); var iterator = gpsStatus.Satellites.Iterator(); while (iterator.HasNext) { satellitesInView++; var satelite = (GpsSatellite)iterator.Next(); if (satelite.UsedInFix()) { satellitesInUse++;// in present time we cannot find any satellites in use, so satellitesInUse is useless } } _satellitesCount = satellitesInView; }
private LocationStatus GetLocationStatus(GpsEvent e) { switch (e) { case GpsEvent.FirstFix: return(LocationStatus.Started); case GpsEvent.SatelliteStatus: if (_lastLocation != null) { _isGpsFix = (SystemClock.ElapsedRealtime() - _lastLocationMillis) < 3000; } return(_isGpsFix ? LocationStatus.Started : LocationStatus.Initializing); case GpsEvent.Stopped: return(LocationStatus.Stopped); case GpsEvent.Started: return(LocationStatus.Started); default: return(LocationStatus.Stopped); } }
public void OnGpsStatusChanged([GeneratedEnum] GpsEvent e) { }
public void OnGpsStatusChanged(GpsEvent e) // GpsStatus.IListener { if (locationManager != null) { gpsStatus = locationManager.GetGpsStatus(gpsStatus); switch (e) { case GpsEvent.FirstFix: status = IDeviceGpsStatus.FirstFix; DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString()); break; case GpsEvent.SatelliteStatus: if (gpsStatus != null) { gpsSatellitesVisible = 0; gpsSatellitesUsedInFix = 0; gpsSatellitesWithEphemeris = 0; gpsSatellitesWithAlmanac = 0; var satellites = gpsStatus.Satellites; if (satellites != null) { Java.Util.IIterator iterator = satellites.Iterator(); { while (iterator.HasNext) { gpsSatellitesVisible++; var s = (GpsSatellite)iterator.Next(); if (s.UsedInFix()) { gpsSatellitesUsedInFix++; } if (s.HasEphemeris) { gpsSatellitesWithEphemeris++; } if (s.HasAlmanac) { gpsSatellitesWithAlmanac++; } } } if (gpsSatellitesUsedInFix > 3) { status = IDeviceGpsStatus.Connected; } } } break; case GpsEvent.Started: status = IDeviceGpsStatus.Started; DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString()); break; case GpsEvent.Stopped: status = IDeviceGpsStatus.Stopped; DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString()); break; } if (listener != null) { listener.OnGpsStatusUpdate(); } } }
public override void OnReceiveLocation(BDLocation lct) { if (lct == null) { return; } try { var msg = $"OnReceiveLocation:{lct.Latitude} Latitude:{lct.Longitude} Address:{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}"; Android.Util.Log.Info("位置:", msg); //ToastUtils.ShowSingleToast(msg); GlobalSettings.Latitude = lct.Latitude; GlobalSettings.Longitude = lct.Longitude; new Thread(async() => { if (lct != null && !GlobalSettings.IsNotConnected) { var _conn = App.Resolve <LocalDatabase>(); var tracking = new TrackingModel() { StoreId = Settings.StoreId, BusinessUserId = Settings.UserId, BusinessUserName = Settings.UserRealName, Latitude = lct.Latitude, Longitude = lct.Longitude, CreateDateTime = DateTime.Now, Province = lct.Province, County = lct.Country, City = lct.City, //Town = lct.Town, Address = lct.Address?.Street }; var gpsEvent = new GpsEvent() { Latitude = lct.Latitude, Longitude = lct.Longitude, CreateTime = DateTime.Now, Address = $"{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}" }; var cg = await _conn.GpsEvents.CountAsync(); var lg = await _conn.LocationSyncEvents.CountAsync(); if (cg > 50) { await _conn.ResetGpsEvents(); } if (lg > 50) { await _conn.ResetLocationSyncEvents(); } //存储本地 if (!string.IsNullOrWhiteSpace(gpsEvent.Address)) { await _conn.InsertAsync(gpsEvent); } if (!string.IsNullOrWhiteSpace(tracking.Address)) { await _conn.InsertAsync(tracking); } } }).Start(); } catch (Java.Lang.Exception ex) { Android.Util.Log.Error("上报", ex.Message); } }
public void OnGpsStatusChanged(GpsEvent e) { int satellitesInView = 0; int satellitesInUse = 0; var gpsStatus = _gpsLocationManager.GetGpsStatus(null); var iterator = gpsStatus.Satellites.Iterator(); while (iterator.HasNext) { satellitesInView++; var satelite = (GpsSatellite)iterator.Next(); if (satelite.UsedInFix()) satellitesInUse++;// in present time we cannot find any satellites in use, so satellitesInUse is useless } _satellitesCount = satellitesInView; }