Example #1
0
        // Obtener el mensaje de estatus de la orden y los marcadores
        // de posición en el mapa.
        public static OrderWithStatus FromOrder(Order order)
        {
            // Para simular un proceso real en el backend,
            // simularemos cambios en el estatus basándonos en
            // el tiempo transcurrido desde que la orden fue realizad
            string        Message;
            List <Marker> Markers;
            // Tiempo en que se despacha a entrega el pedido.
            var DispatchTime = order.CreatedTime.Add(PreparationDuration);

            if (DateTime.Now < DispatchTime)
            {
                Message = "Preparando";
                Markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < DispatchTime + DeliveryDuration)
            {
                Message = "En Camino";
                //Simular la pocision del repartidorr
                var StartPosition = ComputeStartPosition(order);
                var PropotionOfDeliveryCompleted =
                    Math.Min(1, (DateTime.Now - DispatchTime).TotalMilliseconds
                             / DeliveryDuration.TotalMilliseconds);
                var DrivePosition = LatLong.Interpolate(
                    StartPosition, order.DeliveryLocation,
                    PropotionOfDeliveryCompleted);
                Markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation),
                    ToMapMarker("Repartidor", DrivePosition, showPopup: true),
                };
            }
            else
            {
                Message = "Entregado";
                Markers = new List <Marker>
                {
                    ToMapMarker("Ubicacion de entrea", order.DeliveryLocation, showPopup: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = Message,
                MapMarkers = Markers,
            });
        }
        public static OrderWithStatus FromOrder(Order order)
        {
            string        Message;
            List <Marker> Markers;

            var DispatchTime = order.CreatedTime.Add(PreparationDuration);

            if (DateTime.Now < DispatchTime)
            {
                Message = "Preparando";
                Markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < DispatchTime + DeliveryDuration)
            {
                Message = "En camino";
                var StartPosition = ComputeStartPosition(order);
                var ProportionOfDeliveryCompleted = Math.Min(1,
                                                             (DateTime.Now - DispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds);

                var DriverPosition = LatLong.Interpolate(
                    StartPosition,
                    order.DeliveryLocation,
                    ProportionOfDeliveryCompleted);

                Markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation),
                    ToMapMarker("Repartidor", DriverPosition, showPopup: true)
                };
            }
            else
            {
                Message = "Entregado";

                Markers = new List <Marker>
                {
                    ToMapMarker("Ubicación de entrega", order.DeliveryLocation, showPopup: true)
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = Message,
                MapMarkers = Markers
            });
        }
        public static OrderWithStatus FromOrder(Order order)
        {
            // To simulate a real backend process, we fake status updates based on the amount
            // of time since the order was placed
            string        _message;
            bool          _isDelivered = false;
            List <Marker> _markers;
            var           dispatchTime = order.CreatedTime.Add(PreparationDuration);

            if (DateTime.Now < dispatchTime)
            {
                _message = "Preparando";
                _markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < dispatchTime + DeliveryDuration)
            {
                _message = "En ruta a entrega";

                var startPosition = ComputeStartPosition(order);
                var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds);
                var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted);
                _markers = new List <Marker>
                {
                    ToMapMarker("Usted", order.DeliveryLocation),
                    ToMapMarker("Repartidor", driverPosition, showPopup: true),
                };
            }
            else
            {
                _message     = "Entregado";
                _isDelivered = true;
                _markers     = new List <Marker>
                {
                    ToMapMarker("Lugar de entrega", order.DeliveryLocation, showPopup: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = _message,
                IsDelivered = _isDelivered,
                MapMarkers = _markers,
            });
        }
        public static OrderWithStatus FromOrder(Order order)
        {
            // To simulate a real backend process, we fake status updates based on the amount
            // of time since the order was placed
            string         statusText;
            IList <Marker> mapMarkers;
            var            dispatchTime     = order.CreatedTime.AddSeconds(10);
            var            deliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch

            if (DateTime.Now < dispatchTime)
            {
                statusText = "Preparing";
                mapMarkers = new List <Marker>
                {
                    ToMapMarker("You", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < dispatchTime + deliveryDuration)
            {
                statusText = "Out for delivery";

                var startPosition = ComputeStartPosition(order);
                var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / deliveryDuration.TotalMilliseconds);
                var driverPostion = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted);
                mapMarkers = new List <Marker>
                {
                    ToMapMarker("You", order.DeliveryLocation),
                    ToMapMarker("Driver", driverPostion, showPopup: true)
                };
            }
            else
            {
                statusText = "Delivered";
                mapMarkers = new List <Marker>
                {
                    ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true)
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = statusText,
                MapMarkers = mapMarkers
            });
        }
Example #5
0
        public static OrderWithStatus FromOrder(Order order)
        {
            string        Massage;
            List <Marker> Markers;
            var           DespacthTime = order.CreatedTime.Add(PreparationDuration);

            if (DateTime.Now < DespacthTime)
            {
                Massage = "Preparando";
                Markers = new List <Marker>
                {
                    ToMapMarker("usted", order.DeliveryLocation, showpoput: true)
                };
            }
            else if (DateTime.Now < DespacthTime + DeliveryDuration)
            {
                Massage = "en camino";
                var startPosition = ComputeStartPosition(order);
                var proportionOfDelliveryCompleted = Math.Min(1, (DateTime.Now - DespacthTime)
                                                              .TotalMilliseconds / DeliveryDuration.TotalMilliseconds);
                var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDelliveryCompleted);
                Markers = new List <Marker>
                {
                    ToMapMarker("usted", order.DeliveryLocation),
                    ToMapMarker("repartodr", driverPosition, showpoput: true),
                };
            }
            else
            {
                Massage = "enttegado";
                Markers = new List <Marker>
                {
                    ToMapMarker("ubicaciòn de entrega1",
                                order.DeliveryLocation, showpoput: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = Massage,
                MapMarkers = Markers,
            });
        }
Example #6
0
 public static LatLong Interpolate(LatLong start, LatLong end, double proportion)
 {
     return(new LatLong(start.Latitude + (end.Latitude - start.Latitude) * proportion, start.Longitude + (end.Longitude - start.Longitude) * proportion));
 }
 static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false) => new Marker
 {
     Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup
 };