Exemple #1
0
        /* Method to get the nearest station, with available bikes, to a given point */
        private WebProxyService.Station getNearestAvailableStation(WebProxyService.Station[] stations, GeoCoordinate pointCoord, string contract)
        {
            WebProxyService.Station nearestStation = getNearestStation(stations, pointCoord);
            WebProxyService.Station station        = webProxyService.GetStation(nearestStation.number, contract);

            while (station.totalStands.availabilities.bikes == 0 && station.totalStands.availabilities.electricalBikes == 0)
            {
                stations       = stations.Where((source, index) => index != Array.IndexOf(stations, nearestStation)).ToArray();
                nearestStation = getNearestStation(stations, pointCoord);
                station        = webProxyService.GetStation(nearestStation.number, contract);
            }

            return(nearestStation);
        }
Exemple #2
0
        /* Method to get the nearest station to a given point */
        private WebProxyService.Station getNearestStation(WebProxyService.Station[] stations, GeoCoordinate pointCoord)
        {
            WebProxyService.Station nearestStation = null;
            double bestDistance = 0;

            foreach (var station in stations)
            {
                if (nearestStation == null)
                {
                    nearestStation = station;
                    bestDistance   = pointCoord.GetDistanceTo(new GeoCoordinate(station.position.latitude, station.position.longitude));
                }
                else if (pointCoord.GetDistanceTo(new GeoCoordinate(station.position.latitude, station.position.longitude)) < bestDistance)
                {
                    nearestStation = station;
                    bestDistance   = pointCoord.GetDistanceTo(new GeoCoordinate(station.position.latitude, station.position.longitude));
                }
            }

            return(nearestStation);
        }
Exemple #3
0
        /* Method to a list of routing between two addresses */
        public List <Routing> GetItineraryBetweenTwoAddress(string startingAddress, string destination)
        {
            Point startingAddressPoint = getCoordinatesFromAddress(startingAddress);
            Point destinationPoint     = getCoordinatesFromAddress(destination);

            List <Routing> routings = new List <Routing>();

            if (startingAddressPoint != null && destinationPoint != null)
            {
                WebProxyService.Station[] stations = webProxyService.GetStationsForContract(startingAddressPoint.city);

                Itinerary footItinerary = getFootItinerary(startingAddressPoint, destinationPoint);

                if (stations != null && stations.Length > 0)
                {
                    GeoCoordinate startPointCoord = new GeoCoordinate(Convert.ToDouble(startingAddressPoint.latitude), Convert.ToDouble(startingAddressPoint.longitude));
                    GeoCoordinate endPointCoord   = new GeoCoordinate(Convert.ToDouble(destinationPoint.latitude), Convert.ToDouble(destinationPoint.longitude));

                    WebProxyService.Station startPointNearestStation = getNearestAvailableStation(stations, startPointCoord, startingAddressPoint.city);
                    WebProxyService.Station endPointNearestStation   = getNearestAvailableStation(stations, endPointCoord, destinationPoint.city);

                    List <Itinerary> itineraries = new List <Itinerary>();

                    itineraries.Add(getFootItinerary(startingAddressPoint, new Point(startPointNearestStation.position.latitude, startPointNearestStation.position.longitude)));
                    itineraries.Add(getBikeItinerary(new Point(startPointNearestStation.position.latitude, startPointNearestStation.position.longitude), new Point(endPointNearestStation.position.latitude, endPointNearestStation.position.longitude)));
                    itineraries.Add(getFootItinerary(new Point(endPointNearestStation.position.latitude, endPointNearestStation.position.longitude), destinationPoint));


                    float total_duration = 0;

                    foreach (var itineray in itineraries)
                    {
                        total_duration += itineray.routes[0].duration;
                    }

                    if (footItinerary.routes[0].duration < total_duration)
                    {
                        routings.Add(createRouting("Foot", footItinerary.routes[0].duration, startingAddressPoint,
                                                   destinationPoint, footItinerary.routes[0].legs[0].steps));
                    }
                    else
                    {
                        routings.Add(createRouting("Foot", itineraries[0].routes[0].duration, startingAddressPoint,
                                                   new Point(startPointNearestStation), itineraries[0].routes[0].legs[0].steps));

                        routings.Add(createRouting("Bike", itineraries[1].routes[0].duration, new Point(startPointNearestStation),
                                                   new Point(endPointNearestStation), itineraries[1].routes[0].legs[0].steps));

                        routings.Add(createRouting("Foot", itineraries[2].routes[0].duration, new Point(endPointNearestStation),
                                                   destinationPoint, itineraries[2].routes[0].legs[0].steps));

                        stationLog.AddLogForStation(startPointNearestStation.name);
                        stationLog.AddLogForStation(endPointNearestStation.name);
                    }
                }
                else
                {
                    routings.Add(createRouting("Foot", footItinerary.routes[0].duration, startingAddressPoint,
                                               destinationPoint, footItinerary.routes[0].legs[0].steps));
                }
            }

            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");

            return(routings);
        }
 public Point(WebProxyService.Station station)
 {
     this.latitude  = station.position.latitude;
     this.longitude = station.position.longitude;
     this.station   = station;
 }