public async Task <List <Coordinate> > GetHereRoutes(CoordinateOrLocation fromLocation, CoordinateOrLocation toLocation) { var from = await GetCoordinate(fromLocation); var to = await GetCoordinate(toLocation); var result = await _hereService.GetRoutes(DateTime.Now, from, to); if (result == null) { return(null); } var coords = result.Response.Route.FirstOrDefault()?.Shape; if (coords == null) { return(null); } var nfi = new CultureInfo("en-US", false).NumberFormat; nfi.NumberDecimalSeparator = "."; return(coords .Select(c => { var pair = c.Split(','); return new Coordinate() { Latitude = double.Parse(pair[0], nfi), Longitude = double.Parse(pair[1], nfi) }; }) .ToList()); }
private async Task <List <TargetRoute> > GetHereRoutes(DateTime time, Coordinate from, Coordinate to, bool allowPedestrian = false) { var result = await _hereService.GetRoutes(time, from, to); if (result == null && allowPedestrian) { result = await _hereService.GetRoutes(time, from, to, "pedestrian"); } if (result == null) { return(null); } return(result.Response.Route .Select(r => { var maneuvers = r.Leg.FirstOrDefault().Maneuver; var transports = r.PublicTransportLine; var routes = new List <TransportRoute>(); int i = 0; int travelTime = 0; TransportRoute route = new TransportRoute() { Transport = "Пешком", Points = new List <RoutePoint>() }; foreach (var maneuver in maneuvers) { var p = new RoutePoint { Description = maneuver.StopName, Time = time.AddSeconds(travelTime).ToString("HH:mm:ss"), Coordinate = new Coordinate { Latitude = maneuver.Position.Latitude, Longitude = maneuver.Position.Longitude } }; route.Points.Add(p); travelTime += maneuver.TravelTime; if (maneuver.Action == "enter") { if (route.Points.Count() > 1) { routes.Add(route); } route = new TransportRoute() { Transport = $"Автобус {transports[i].LineName}", Points = new List <RoutePoint>() { p } }; i++; } if (maneuver.Action == "leave") { routes.Add(route); route = new TransportRoute() { Transport = $"Пешком", Points = new List <RoutePoint>() }; } } routes.Add(route); return new TargetRoute { Routes = routes, TravelTime = r.Leg.FirstOrDefault().TravelTime }; }) .ToList()); }