private IEnumerable <TrailMatchResult> CheckForCompletedTrails(RideLocationDto location) { var threshold = locationMatchThreshold; var keys = currentTrailCache.Keys.ToList(); foreach (var key in keys) { var cache = currentTrailCache[key]; var trail = cache.TrailAnalysis; var lastLocation = trail.Locations.Last(); bool completed = IsWithinThresholdAndClosest(lastLocation, location, threshold); if (!completed) { continue; } if (cache.LocationsHitPercent < 90) { continue; } yield return(new TrailMatchResult { TrailId = trail.TrailId, StartIdx = currentTrailCache[key].StartIdx, EndIdx = ride.Locations.IndexOf(location), }); currentTrailCache.Remove(key); } }
public void AddLocation(RideLocationDto location) { Debug.WriteLine(location); lastLocation = location; LocationChanged?.Invoke(new LocationChangedEventArgs { Location = location }); }
private bool IsClosestPoint(RideLocationDto nextLocation, ILatLng trailLocation, double lastDistance) { if (nextLocation == null) { return(true); } double nextDistance = nextLocation.GetDistanceM(trailLocation); return(lastDistance < nextDistance); }
public void Stop() { if (!isRunning) { return; } DependencyService.Get <INativeGeoUtility>().Stop(); isRunning = false; lastLocation = null; }
public void OnLocationChanged(Android.Locations.Location location) { if (location.Accuracy > 20) { return; } var locationDto = new RideLocationDto { Timestamp = DateTimeOffset.FromUnixTimeMilliseconds(location.Time).DateTime, Latitude = location.Latitude, Longitude = location.Longitude, AccuracyInMetres = location.Accuracy, Mph = location.Speed * 2.23694, Altitude = location.Altitude, }; App.Current.MainContext.GeoUtility.AddLocation(locationDto); }
private bool IsWithinThresholdAndClosest(ILatLng trailLocation, RideLocationDto location, int threshold) { double distance = trailLocation.GetDistanceM(location); bool isWithinThreshold = distance <= threshold; if (!isWithinThreshold) { return(false); } int locationIdx = ride.Locations.IndexOf(location); var nextLocation = ride.Locations .Where(i => i.Timestamp > location.Timestamp) .FirstOrDefault(); return(IsClosestPoint(nextLocation, trailLocation, distance)); }
private void CheckNewMatchingTrails(RideLocationDto location) { var threshold = locationMatchThreshold; var unmatchedTrails = allTrails .Where(i => !currentTrailCache.ContainsKey(i.TrailId)); foreach (var trail in unmatchedTrails) { var firstLocation = trail.Locations.First(); bool matchesFirstLocation = IsWithinThresholdAndClosest(firstLocation, location, threshold); if (matchesFirstLocation) { var cache = new TrailCache(trail, ride.Locations.IndexOf(location)); cache.LocationsHit.Add(firstLocation); currentTrailCache.Add(trail.TrailId, cache); } } }
private void CheckCachedTrails(RideLocationDto location) { var threshold = locationMatchThreshold; foreach (var trail in currentTrailCache) { var locations = trail.Value.TrailAnalysis.Locations; var closeLocations = locations.Where(i => i.GetDistanceM(location) <= threshold); if (closeLocations.Any()) { trail.Value.MissedPoints = 0; foreach (var closeLocation in closeLocations) { trail.Value.LocationsHit.Add(closeLocation); } } else { trail.Value.MissedPoints++; } } }