Ejemplo n.º 1
0
        public RouteInformation FindNearestWay(RouteInformation routeInformation)
        {
            PointLatLng userLoc                = new PointLatLng(routeInformation.startCoordinatesLat, routeInformation.startCoordinatesLng);
            PointLatLng nearestPoint           = new PointLatLng();
            string      excursionRoute         = String.Empty;
            double      maxDistance            = Double.MaxValue;
            int         IdVisitedExcursionRout = 0;

            using (DbContextTourists dbContext = new DbContextTourists())
            {
                List <Route> routes = dbContext.Routes.Where(a => a.CityID == routeInformation.IdCurrentCity).ToList();

                foreach (var item in routes)
                {
                    List <PointLatLng> pointsStartedRoute = Helper.StringToListLatLng(item.CoordinatesStartingPointsRouteOGC);
                    foreach (var pointSR in pointsStartedRoute)
                    {
                        double distance = Map.GetRouteDistance(userLoc, pointSR);
                        if (distance < maxDistance)
                        {
                            maxDistance            = distance;
                            nearestPoint           = pointSR;
                            excursionRoute         = Helper.DeleteLetterFromString(item.CoordinatesOGC);
                            IdVisitedExcursionRout = item.ID;
                        }
                    }
                }
            }
            return(PrepareRouteInformation(routeInformation, userLoc, nearestPoint, IdVisitedExcursionRout, excursionRoute));
        }
Ejemplo n.º 2
0
        private RouteInformation PrepareRouteInformation(RouteInformation routeInformation, PointLatLng start,
                                                         PointLatLng finish, int idVisitedRoute, string excrustionRoute, int countExcurisonRoutes = -1)
        {
            var diraction = Map.GetDiraction(start, finish);

            routeInformation.SetInformationAboutRoute(diraction, idVisitedRoute);
            routeInformation.ExcursionRoute = excrustionRoute;

            if (routeInformation.listIdVisitedRoutes.Count == countExcurisonRoutes)
            {
                routeInformation.listIdVisitedRoutes.Clear();
            }

            return(routeInformation);
        }