Exemplo n.º 1
0
 private void GetGoogleInstance(ISession session)
 {
     if (_googleDirectionsService == null)
     {
         _googleDirectionsService = new DirectionsService(session);
     }
 }
Exemplo n.º 2
0
        public JsonResult DeliverWithinDays(string days)
        {
            var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), Convert.ToInt32(days));
            var routes     = DateFilter.getRoutesWithinDays(company.Routes.ToList(), Convert.ToInt32(days));

            Response.StatusCode = (int)HttpStatusCode.OK;
            List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>();

            foreach (Delivery delivery in deliveries)
            {
                ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel();
                model.Client        = delivery.Client;
                model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address);
                model.ID            = delivery.ID;

                string clientName      = delivery.Client.FirstName + " " + delivery.Client.LastName;
                string currentStatus   = StatusExtension.DisplayName(delivery.DeliveryStatus.Status);
                string deliverByDate   = delivery.DeliverBy.Value.Date.ToString();
                string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" "));

                model.clientName    = clientName;
                model.currentStatus = currentStatus;
                model.deliverBy     = deliverByString;
                delsWithAddress.Add(model);
            }
            MapObjects result = new MapObjects(deliveries, routes, delsWithAddress, company);

            return(Json(result));
        }
Exemplo n.º 3
0
        private async void ShowRouteToPlace(Place place)
        {
            ProgressDialog pleaseWaitDialog = new ProgressDialog(this);

            pleaseWaitDialog.SetMessage(GetString(Resource.String.please_wait));
            pleaseWaitDialog.SetCancelable(false);
            pleaseWaitDialog.Show();

            try
            {
                MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                nearestPlace = place;
                Route route = await DirectionsService.GetShortestRoute(
                    mapFragment.MyLocation, place.geometry.location);

                mapFragment.DrawRouteToPlace(route, nearestPlace);
            }
            catch (ApiCallException)
            {
            }
            catch (DirectionsException)
            {
            }
            finally
            {
                pleaseWaitDialog.Cancel();
            }
        }
Exemplo n.º 4
0
        public IActionResult MapDelivery(int?id)
        {
            var delivery = _context.Deliveries
                           .Include(d => d.Client)
                           .Include(d => d.Client.Address)
                           .Include(d => d.DeliveryStatus)
                           .SingleOrDefault(d => d.ID == id);
            double locationLat = delivery.Client.Address.Lat;
            double locationLng = delivery.Client.Address.Lng;
            string clientName  = delivery.Client.FirstName + " " + delivery.Client.LastName;

            string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status);

            if (delivery.DeliveryStatus.Status.Equals(Status.Delivered))
            {
                DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value;
                deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
            }

            string addressString              = DirectionsService.getStringFromAddress(delivery.Client.Address);
            string deliverByDate              = delivery.DeliverBy.Value.Date.ToString();
            string deliverByString            = deliverByDate.Substring(0, deliverByDate.IndexOf(" "));
            DriverSingleDeliveryMapView model = new DriverSingleDeliveryMapView(locationLat, locationLng, clientName, deliverByString, deliverytatusString, addressString);

            return(View(model));
        }
Exemplo n.º 5
0
        public IActionResult Index()
        {
            var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), 2);
            var depots     = company.PickUpLocations.ToList();
            List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>();

            foreach (Delivery delivery in deliveries)
            {
                ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel();
                model.Client        = delivery.Client;
                model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address);
                model.ID            = delivery.ID;

                string clientName      = delivery.Client.FirstName + " " + delivery.Client.LastName;
                string currentStatus   = StatusExtension.DisplayName(delivery.DeliveryStatus.Status);
                string deliverByDate   = delivery.DeliverBy.Value.Date.ToString();
                string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" "));

                model.clientName    = clientName;
                model.currentStatus = currentStatus;
                model.deliverBy     = deliverByString;
                delsWithAddress.Add(model);
            }
            MapObjects objects = new MapObjects(deliveries, depots, company.Routes.ToList(), delsWithAddress, company);

            return(View(objects));
        }
Exemplo n.º 6
0
        public static void Testar(ISession session)
        {
            var googleDirectionsService = new DirectionsService(session);

            var googleResult = googleDirectionsService.GetDirections(new GeoCoordinate(40.780599, -73.968862), new List <GeoCoordinate>(), new GeoCoordinate(40.781939, -73.965123));
            var googleWalk   = GoogleWalk.Get(googleResult);

            var proximo = googleWalk.NextStep(new GeoCoordinate(40.780573, -73.968842));
        }
Exemplo n.º 7
0
        public void testGetDirections()
        {
            PickUpAddress     pickUpAddress = new PickUpAddress("23 London Road", "Flat 2", "Brighton", "BN2 4PN");
            ClientAddress     clientAddress = new ClientAddress("25 London Road", "Flat 2", "Brighton", "BN2 4PN");
            DirectionsService service       = new DirectionsService();

            service.options = new AppProperties();
            Directions result = service.getDirectionsFromAddresses(pickUpAddress, clientAddress);

            Assert.Equal("23 London Road Flat 2 Brighton BN2 4PN", result.From);
            Assert.Equal("25 London Road Flat 2 Brighton BN2 4PN", result.To);
        }
Exemplo n.º 8
0
        public async Task GetResult_OriginDestinationKey_StatusOK()
        {
            //Arrange
            var controller = new DirectionsService();

            controller.Parameters.Origin      = new Location(46.436458, 30.741378);
            controller.Parameters.Destination = new Location(46.437828, 30.726247);
            controller.Parameters.Key         = "AIzaSyA3YhAyyckDAMFGuVR7yRI-fG_NATvL8Yk";

            //Act
            var result = await controller.GetResultAsync();

            //Assert
            Assert.Equal("OK", result?.Status);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GoogleMapsApiClient"/> class.
        /// </summary>
        /// <param name="apiKey">
        /// The api key.
        /// </param>
        public GoogleMapsApiClient(string apiKey)
        {
            var url = EndPointUris.GetBaseUri();

            var httpClientHandler = new HttpClientHandler();
            var httpClient        = new HttpClientAdapter(
                new HttpClient(httpClientHandler, true)
            {
                BaseAddress = url
            });
            var webApi = new WebApi(httpClient, apiKey);

            PlaceSearch       = new PlaceSearch(webApi);
            GeocodingService  = new GeocodingService(webApi);
            DirectionsService = new DirectionsService(webApi);
        }
Exemplo n.º 10
0
        public IActionResult MapRoute(int?id)
        {
            Route        route = driver.Routes.Where(r => r.ID == id).FirstOrDefault();
            MapRouteView model = new MapRouteView();

            foreach (Delivery delivery in route.Deliveries)
            {
                model.waypoints.Add(DirectionsService.getStringFromAddressInLatLngFormat(delivery.Client.Address));
            }
            model.depotAddress     = DirectionsService.getStringFromAddressInLatLngFormat(route.PickUpAddress);
            model.overallRouteTime = route.OverallTimeRequired + "h";
            model.routeDistance    = route.OverallDistance + "mi";


            return(View(model));
        }
Exemplo n.º 11
0
        public async Task GetResult_OriginDestinationKeyModeDepartureTime_StatusOK()
        {
            //Arrange
            var controller = new DirectionsService();

            controller.Parameters.Origin        = new Location(46.436458, 30.741378);
            controller.Parameters.Destination   = new Location(46.437828, 30.726247);
            controller.Parameters.Key           = "AIzaSyA3YhAyyckDAMFGuVR7yRI-fG_NATvL8Yk";
            controller.Parameters.Mode          = Modes.Transit;
            controller.Parameters.DepartureTime = DateTime.Parse("11/01/2018 16:00");

            //Act
            var result = await controller.GetResultAsync();

            //Assert
            Assert.Equal("OK", result?.Status);
        }
Exemplo n.º 12
0
        static Task <RouteInfo> GetRouteBetween(GeoCoordinates origin, GeoCoordinates destination)
        {
            try
            {
                return(DirectionsService.ComputeApproximateDrivingInfo(
                           Program.GoogleApiKey,
                           origin, destination));
            }
            catch (ApplicationException ex)
            {
                Program.LogError($"Failure in {nameof(SinglePassengerRideMatcher)}: {ex.Message}");

                return(Task.FromResult(new RouteInfo(new GeoPolyline(new[]
                {
                    origin,
                    destination
                }))));
            }
        }
Exemplo n.º 13
0
        public async Task GetResult_OriginDestinationKeyWaypointsDepartureTime_StatusOK()
        {
            //Arrange
            var controller = new DirectionsService();

            controller.Parameters.Origin        = new Location(46.436458, 30.741378);
            controller.Parameters.Destination   = new Location(46.437828, 30.726247);
            controller.Parameters.Key           = "AIzaSyA3YhAyyckDAMFGuVR7yRI-fG_NATvL8Yk";
            controller.Parameters.DepartureTime = DateTime.Parse("11/07/2018 16:00");
            controller.Parameters.Optimize      = true;
            controller.Parameters.Waypoints.Add(new Location(46.468184, 30.741464));
            controller.Parameters.Waypoints.Add(new Location(46.459931, 30.749942));

            //Act
            var result = await controller.GetResultAsync();

            //Assert
            Assert.Equal("OK", result?.Status);
        }
Exemplo n.º 14
0
        static Task <RouteInfo> GetRouteWithPassenger(UserRideOffer offer, MatchableRideRequest passenger)
        {
            try
            {
                return(DirectionsService.ComputeApproximateDrivingInfo(
                           Program.GoogleApiKey,
                           offer.RideOffer.Trip.Source,
                           offer.RideOffer.Trip.Destination,
                           passenger.Request.RideRequest.Trip.Source,
                           passenger.Request.RideRequest.Trip.Destination));
            }
            catch (ApplicationException ex)
            {
                Program.LogError($"Failure in {nameof(SinglePassengerRideMatcher)}: {ex.Message}");

                return(Task.FromResult(new RouteInfo(new GeoPolyline(new[]
                {
                    offer.RideOffer.Trip.Source,
                    passenger.Request.RideRequest.Trip.Source,
                    passenger.Request.RideRequest.Trip.Destination,
                    offer.RideOffer.Trip.Destination
                }))));
            }
        }
Exemplo n.º 15
0
 public GoogleDirectionsTests()
 {
     fixture = new DirectionsService(GOOGLE_PLACES_API_KEY);
 }
Exemplo n.º 16
0
        private async void ShowRouteToNearestAddress(string query)
        {
            CheckInternetConnection();

            if (!string.IsNullOrWhiteSpace(query))
            {
                ProgressDialog pleaseWaitDialog = new ProgressDialog(this);
                pleaseWaitDialog.SetMessage(GetString(Resource.String.please_wait));
                pleaseWaitDialog.SetCancelable(false);
                pleaseWaitDialog.Show();

                try
                {
                    MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                    if (mapFragment.MyLocation == null)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.my_location_unavaliable),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    List <Place> places = await PlacesService.GetPlacesByQuery(query, mapFragment.MyLocation);

                    if (places.Count == 0)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.no_places_found),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    nearestPlace = null;
                    Route shortestRoute = null;
                    foreach (var place in places)
                    {
                        var route = await DirectionsService.GetShortestRoute(
                            mapFragment.MyLocation, place.geometry.location);

                        if (shortestRoute == null)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                        else if (route.legs[0].distance.value < shortestRoute.legs[0].distance.value)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                    }

                    mapFragment.DrawRouteToPlace(shortestRoute, nearestPlace);
                    OnPrepareOptionsMenu(actionBarMenu);
                    actionBarMenu.FindItem(Resource.Id.action_add_to_fav).SetVisible(true);
                }
                catch (ApiCallException)
                {
                }
                catch (NearbyPlacesSearchException)
                {
                }
                catch (DirectionsException)
                {
                }
                finally
                {
                    pleaseWaitDialog.Cancel();
                }
            }
        }