public async Task<XLocation> GetQuickLocation() { Setup(); var loc = new XLocation(); _cancelSource = new CancellationTokenSource(); await _geolocator.GetPositionAsync(1500, _cancelSource.Token, false) .ContinueWith(t => { if (t.IsCanceled || t.IsFaulted) { var x = new XLocation(); x.IsResolved = false; x.Status = XPositionStatus.NotAvailble; return x; } 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 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 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 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); }
/// <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; }
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 void Init() { CurrentLocation = new XLocation(); }
private void Init() { CurrentLocation = new XLocation(); }
void _locationService_LocationUpdated(object sender, EventArgs e) { CurrentLocation = _locationService.CurrentLocation; }
public static XLocation ConvertXLocation(Geocoordinate geocoordinate, XLocation existing) { geocoordinate.CopyProperties(existing); return existing; }
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 double Distance(double lat, double lng, XLocation b) { var xloca = new XLocation {Latitude = lat, Longitude = lng}; return DistanceHelper.DistanceBetween(xloca, b, DistanceType.Kilometers); }
public double Distance(double lat, double lng, XLocation b) { //Manual distance calculation. var R = 6371; // Radius of the earth in km var lat1 = lat; var lon1 = lng; var lat2 = b.Latitude; var lon2 = b.Longitude; var dLat = deg2rad(lat2 - lat1); var dLon = deg2rad(lon2 - lon1); var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2) ; var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); var d = R * c; // Distance in km return d; }
public async Task<XLocation> GetQuickLocation() { Init(); if (!string.IsNullOrWhiteSpace(_locationProvider) && _locationManager != null) { var l = _locationManager.GetLastKnownLocation(_locationProvider); if (l != null) { var loc = new XLocation(); loc.Latitude = l.Latitude; loc.Longitude = l.Longitude; loc.Accuracy = l.Accuracy; loc.Heading = l.Bearing; loc.IsEnabled = true; loc.IsResolved = true; loc.Status = XPositionStatus.Ready; return loc; } } return new XLocation(); }
public double Distance(double lat, double lng, XLocation b) { return LocationHelpers.Distance(lat, lng, b); }
void init() { CurrentLocation = new XLocation(); }
async void _getLocation() { CurrentLocation = await _locationService.GetQuickLocation(); }