public void Distance() { var pos1 = new Position(46.83749695f, 16.84976191f); var pos2 = new Position(46.83749276f, 16.84976201f); var distance = GeoHelper.Distance(pos1, pos2); Assert.AreEqual(0.4, distance, 0.01); }
public void GeoHelper_Plot() { // Plot a destination from an origin point using a course and // distance and compare this to a known result from: // // http://www.movable-type.co.uk/scripts/latlong.html var start = new GeoCoordinate("50 03 59N", "005 42 53W"); var end = GeoHelper.Plot(start, 45, 15, GeoHelper.EarthRadiusKilometers); var reference = new GeoCoordinate("50°09′42″N", "005°33′57″W"); Assert.IsTrue(start.Latitude < end.Latitude); Assert.IsTrue(start.Longitude < end.Longitude); Assert.IsTrue(GeoHelper.Distance(end, reference, GeoHelper.EarthRadiusKilometers) < 0.02); // Verify accuracy to within 2% }
public void GeoHelper_Distance() { // Compute the distance between two points on the earth where // we know the distance from the calculator on: // // http://www.movable-type.co.uk/scripts/latlong.html var millCreek = new GeoCoordinate(47.845, -122.248); var rosemont = new GeoCoordinate(47.621, -122.092); var distance = GeoHelper.Distance(millCreek, rosemont, GeoHelper.EarthRadiusKilometers); Assert.IsTrue(27.45 <= distance && distance < 27.55); distance = GeoHelper.Distance(rosemont, millCreek, GeoHelper.EarthRadiusKilometers); Assert.IsTrue(27.45 <= distance && distance < 27.55); }
/// <summary> /// Checks if we need to update data /// </summary> /// <param name="sender"></param> /// <param name="o"></param> private async void HeartbeatTick(object sender, object o) { // We need to skip this iteration if (!_keepHeartbeating || _isHeartbeating) { return; } _isHeartbeating = true; // Heartbeat is alive so we check if we need to update data, based on GameSettings var canRefresh = false; //Collect location data for signature DeviceInfos.Current.CollectLocationData(); // We have no settings yet so we just update without further checks if (GameSetting == null) { canRefresh = true; } else { // Check if we need to update var minSeconds = GameSetting.MapSettings.GetMapObjectsMinRefreshSeconds; var maxSeconds = GameSetting.MapSettings.GetMapObjectsMaxRefreshSeconds; var minDistance = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters; var lastGeoCoordinate = _lastGeopositionMapObjectsRequest; var secondsSinceLast = DateTime.Now.Subtract(BaseRpc.LastRpcRequest).Seconds; if (lastGeoCoordinate == null) { Logger.Write("Refreshing MapObjects, reason: 'lastGeoCoordinate == null'."); canRefresh = true; } else if (secondsSinceLast >= minSeconds) { var metersMoved = GeoHelper.Distance(Geoposition.Coordinate.Point, lastGeoCoordinate.Coordinate.Point); if (secondsSinceLast >= maxSeconds) { Logger.Write($"Refreshing MapObjects, reason: 'secondsSinceLast({secondsSinceLast}) >= maxSeconds({maxSeconds})'."); canRefresh = true; } else if (metersMoved >= minDistance) { Logger.Write($"Refreshing MapObjects, reason: 'metersMoved({metersMoved}) >= minDistance({minDistance})'."); canRefresh = true; } } } // Update! if (!canRefresh) { _isHeartbeating = false; return; } try { await UpdateMapObjects(); } catch (Exception ex) { await ExceptionHandler.HandleException(ex); } finally { _isHeartbeating = false; } }