public async Task DisplayClosestSightAsync() { var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { // using default accuracy var geolocator = new Geolocator(); var pos = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5)); if (pos != null) { CurrentSight = await SightsHelper.FindClosestSightAsync(pos.Coordinate.Point, CurrentTrip, false); } else { // If we can't use the location, we'll just use the first Sight CurrentSight = CurrentTrip.Sights.FirstOrDefault(s => s.IsMySight); } } else { // If we can't use the location, we'll just use the first Sight CurrentSight = CurrentTrip.Sights.FirstOrDefault(s => s.IsMySight); } if (CurrentSight != null) { AppShell.Current.NavigateToPage(typeof(SightDetailPage), CurrentSight.Id.ToString("D")); } }
private static async Task <List <Sight> > GetNearestSights(Geopoint point) { var datamodelService = DataModelServiceFactory.CurrentDataModelService(); // we are just loading the default trip here var trip = await datamodelService.LoadTripAsync(AppSettings.LastTripId); var nearest = await SightsHelper.FindClosestSightsAsync(point, trip, false); return(nearest); }