public static async Task<Location> GetCurrent() { try { return await Task.Run(async () => { Location location = LastLocation; //await Geolocator.RequestAccessAsync(); geolocator = new Geolocator(); geolocator.ReportInterval = 100; geolocator.DesiredAccuracyInMeters = 200; Geoposition pos = Task.FromResult<Geoposition>(await geolocator.GetGeopositionAsync()).Result; location = new Location() { Latitude = pos.Coordinate.Point.Position.Latitude, Longitude = pos.Coordinate.Point.Position.Longitude }; LastLocation = location; return location; }); } catch (Exception ex) { } return null; }
private async Task getRitTime(Location location) { if (location != null) { //checkhowfaraway Response farEnough = Task.FromResult<Response>(await TripRepository.Difference((Location)VindRitFilterVM.SelectedDestination.Location, location)).Result; if(farEnough.Success==true && farEnough.Value!=null) { double distance; double.TryParse(farEnough.Value.ToString(), out distance); double speed = 45; double time = distance / speed; this.RitTime = ": " + time.ToString(); RaiseAll(); } } }
private async void ShowRoute(Location from, Location to) { try { if ((App.Current as App).UserLocation != null) { ClearAllMapItems(); this.Map.Routes.Clear(); //Tijdelijke locatie aanmaken BasicGeoposition tempFrom = new BasicGeoposition(); tempFrom.Longitude = from.Longitude; tempFrom.Latitude = from.Latitude; BasicGeoposition tempTo = new BasicGeoposition(); tempTo.Longitude = to.Longitude; tempTo.Latitude = to.Latitude; //Start en eindpunt ophalen en klaarzetten voor onderstaande vraag Geopoint startpunt = new Geopoint(tempFrom); Geopoint eindpunt = new Geopoint(tempTo); //De route tussen 2 punten opvragen MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync(startpunt, eindpunt); if (routeResult.Status == MapRouteFinderStatus.Success)//Het is gelukt, we hebben een antwoord gekregen. { MapRouteView viewOfRoute = new MapRouteView(routeResult.Route); viewOfRoute.RouteColor = Color.FromArgb(255, 62, 94, 148); this.Map.Routes.Add(viewOfRoute); //Fit de mapcontrol op de route await this.Map.TrySetViewBoundsAsync(routeResult.Route.BoundingBox, null, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow); } } } catch (Exception ex) { } }
public static async Task<Response> Difference(Location from, Location to) { try { using (HttpClient client = new HttpClient()) { var newObject = JsonConvert.SerializeObject(new { From = from, To = to }); HttpResponseMessage result = await client.PostAsync(URL.TRIPS_DIFFERENECE, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; } catch (Exception ex) { return new Response() { Error = ex.Message.ToString(), Success = false }; } }
private async Task getRitTime(Location location) { if (location != null) { //checkhowfaraway Users_Destinations destination = await DestinationRepository.GetDestinationById(MainViewVM.CurrentTrip.Destinations_ID); Response farEnough = Task.FromResult<Response>(await TripRepository.Difference((Location)destination.Location, location)).Result; if (farEnough.Success == true) { double distance; double.TryParse(farEnough.Value.ToString(), out distance); double speed = 50; double time = distance / speed; this.RitTime = ": " + time.ToString(); RaiseAll(); } } }
public static async Task<List<Bob>> FindBobs(int? rating, DateTime minDate, int BobsType_ID, Location location, int? maxDistance) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var definition = new { Rating = rating, MinDate = minDate, BobsType_ID = BobsType_ID, Location = JsonConvert.SerializeObject(location), MaxDistance = maxDistance }; var newObject = JsonConvert.SerializeObject(definition); HttpResponseMessage result = await client.PostAsync(URL.BOBS_FIND, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); List<Bob> data = JsonConvert.DeserializeObject<List<Bob>>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Response> PostLocation(Location location) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var newObject = JsonConvert.SerializeObject(location); HttpResponseMessage result = await client.PostAsync(URL.USER_LOCATION, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; } catch (Exception ex) { return new Response() { Error = ex.Message.ToString(), Success = false }; } }