public void TestLocationDistance() { int distanceMelbToSyd = 714; //k's. XLocation melbourne = new XLocation { Latitude = -37.8136000, Longitude = 144.9631000 }; XLocation sydney = new XLocation { Latitude = -33.8650000, Longitude = 151.2094000 }; double d = s.Distance(melbourne.Latitude, melbourne.Longitude, sydney); int i = (int)Math.Round(d); Console.WriteLine("Distance to sydney: " + i); //~714k Assert.AreEqual(i, distanceMelbToSyd); }
public double Distance(double lat, double lng, XLocation b) { var firstPoint = new CLLocation(lat, lng); var secondPoint = new CLLocation(b.Latitude, b.Longitude); return(firstPoint.DistanceFrom(secondPoint)); }
public async Task <XLocation> GetQuickLocation() { Setup(); var loc = new XLocation(); _cancelSource = new CancellationTokenSource(); await _geolocator.GetPositionAsync(5000, _cancelSource.Token, false) .ContinueWith(t => { if (t.IsFaulted) { CurrentLocation.IsResolved = false; CurrentLocation.IsEnabled = false; CurrentLocation.Status = XPositionStatus.Disabled; _fire(); return(loc); } if (t.IsCanceled) { return(new XLocation()); } loc.Latitude = t.Result.Latitude; loc.Longitude = t.Result.Longitude; loc.Accuracy = t.Result.Accuracy; loc.Heading = t.Result.Heading; loc.IsEnabled = true; loc.IsResolved = true; loc.Status = XPositionStatus.Ready; return(loc); }, _scheduler); return(loc); }
public async Task <XLocation> GetQuickLocation() { try { var loc = await _locator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(8)); if (loc == null) { return(null); } var xloc = new XLocation { Accuracy = loc.Coordinate.Accuracy, Altitude = loc.Coordinate.Altitude, AltitudeAccuracy = loc.Coordinate.AltitudeAccuracy, Heading = loc.Coordinate.Heading, IsEnabled = true, IsResolved = true, Latitude = loc.Coordinate.Latitude, Longitude = loc.Coordinate.Longitude, Speed = loc.Coordinate.Speed, }; CurrentLocation = xloc; return(xloc); } catch { } return(null); }
public static double Distance(double lat, double lng, XLocation b) { var aCord = new GeoCoordinate(lat, lng); var bCord = new GeoCoordinate(b.Latitude, b.Longitude); return(aCord.GetDistanceTo(bCord)); }
public override int GetHashCode() { var hashCode = 1387378803; hashCode = hashCode * -1521134295 + XLocation.GetHashCode(); hashCode = hashCode * -1521134295 + YLocation.GetHashCode(); return(hashCode); }
public double Distance(double lat, double lng, XLocation b) { var xloca = new XLocation { Latitude = lat, Longitude = lng }; return(DistanceHelper.DistanceBetween(xloca, b, DistanceType.Kilometers)); }
/// <summary> /// Returns the distance in miles or kilometers of any two /// latitude / longitude points. /// </summary> public static double DistanceBetween(XLocation pos1, XLocation pos2, DistanceType type) { double R = (type == DistanceType.Miles) ? 3960 : 6371; double dLat = _toRadian(pos2.Latitude - pos1.Latitude); double dLon = _toRadian(pos2.Longitude - pos1.Longitude); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(_toRadian(pos1.Latitude)) * Math.Cos(_toRadian(pos2.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); double d = R * c; return(d); }
async void _getLocation() { CurrentLocation = await _locationService.GetQuickLocation(); }
public double Distance(double lat, double lng, XLocation b) { return(LocationHelpers.Distance(lat, lng, b)); }
private void Init() { CurrentLocation = new XLocation(); }
void init() { CurrentLocation = new XLocation(); }
async void _locationSensor_LocationUpdated(object sender, EventArgs e) { using (var l = await _lock.LockAsync()) { var wasResolved = IsLocationResolved(); //todo don't have AutoMapper configured - come back to this when configured //CurrentLocation = Mapper.Map(_locationSensor.CurrentLocation, loc); //clone it var loc = new XLocation { Accuracy = _locationSensor.CurrentLocation.Accuracy, IsEnabled = _locationSensor.CurrentLocation.IsEnabled, IsResolved = _locationSensor.CurrentLocation.IsResolved, Latitude = _locationSensor.CurrentLocation.Latitude, Longitude = _locationSensor.CurrentLocation.Longitude, Status = _locationSensor.CurrentLocation.Status, Altitude = _locationSensor.CurrentLocation.Altitude, AltitudeAccuracy = _locationSensor.CurrentLocation.AltitudeAccuracy, Heading = _locationSensor.CurrentLocation.Heading, HeadingAvailable = _locationSensor.CurrentLocation.HeadingAvailable, Speed = _locationSensor.CurrentLocation.Speed }; CurrentLocation = loc; var isResolved = IsLocationResolved(); if (!wasResolved && isResolved) { LowResLocation = new XLocation { Latitude = CurrentLocation.Latitude, Accuracy = CurrentLocation.Accuracy, IsEnabled = CurrentLocation.IsEnabled, IsResolved = CurrentLocation.IsResolved, Longitude = CurrentLocation.Longitude, Status = CurrentLocation.Status }; new LowResLocationUpdatedMessage().Send(); } else if (LowResLocation != null && _locationSensor.Distance(LowResLocation.Latitude, LowResLocation.Longitude, CurrentLocation) > 50) { //todo don't have AutoMapper configured - come back to this when configured //LowResLocation = Mapper.Map<XLocation>(CurrentLocation); LowResLocation = new XLocation { Latitude = CurrentLocation.Latitude, Accuracy = CurrentLocation.Accuracy, IsEnabled = CurrentLocation.IsEnabled, IsResolved = CurrentLocation.IsResolved, Longitude = CurrentLocation.Longitude, Status = CurrentLocation.Status }; new LowResLocationUpdatedMessage().Send(); } _fireEvent(); } }
public static XLocation ConvertXLocation(Geocoordinate geocoordinate, XLocation existing) { geocoordinate.CopyProperties(existing); return(existing); }
public void Init() { CurrentLocation = new XLocation(); Setup(); }
void _locationService_LocationUpdated(object sender, EventArgs e) { CurrentLocation = _locationService.CurrentLocation; }
public override string ToString() { return($"{XLocation.ToString("X")},{YLocation.ToString("X")}"); }