public async Task LoadRoute()
        {
            int positionIndex = 1;

            var googleDirection = await googleMapsApi.GetDirections("18.48849", "-69.971506", "18.5525209", "-69.4376482");

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points));
                CalculateRouteCommand.Execute(positions);

                //Location tracking simulation
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                    if (positions.Count > positionIndex)
                    {
                        UpdatePositionCommand.Execute(positions[positionIndex]);
                        positionIndex++;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("No route", "No route found", "Ok");
            }
        }
예제 #2
0
        public async Task LoadRoute()
        {
            var positionIndex = 1;

            var googleDirection = await googleMapsApi.GetDirections(
                GlobalConfiguration.OriginLatitude, GlobalConfiguration.OriginLongitude,
                GlobalConfiguration.DestinationLatitude, GlobalConfiguration.DestinationLongitude);

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                CalculateRouteCommand.Execute(positions);

                //Location tracking simulation
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                    if (positions.Count > positionIndex)
                    {
                        UpdatePositionCommand.Execute(positions[positionIndex]);
                        positionIndex++;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
            }
        }
예제 #3
0
        private void AddPolyLine()
        {
            _legs.Clear();
            //List<Step> steps = new List<Step>();
            List <Position> directionPolylines = new List <Position>();

            //int iteration = 0;
            foreach (Leg leg in _direction.Routes[0].Legs)
            {
                if (leg.StartAddress == leg.EndAddress)
                {
                    continue;
                }
                for (int i = 0; i < leg.Steps.Count; i++)
                {
                    directionPolylines = directionPolylines.Concat(PolylineHelper.Decode(leg.Steps[i].Polyline.Points).ToList()).ToList();
                    if (i != leg.Steps.Count - 1)
                    {
                        if (leg.Steps[i].Distance.Text.IndexOf(" km") != -1)
                        {
                            leg.Steps[i].Distance.Text = leg.Steps[i].Distance.Text.Replace("km", "kilometers");
                        }
                        else if (leg.Steps[i].Distance.Text.IndexOf(" m") != -1)
                        {
                            leg.Steps[i].Distance.Text = leg.Steps[i].Distance.Text.Replace("m", "meters");
                        }
                        leg.Steps[i].HtmlInstructions += $" for {leg.Steps[i].Distance.Text}";
                    }
                    //steps.Add(leg.Steps[i]);
                }
                _legs.Add(leg);
            }
            CreatePolylinesOnMap(directionPolylines);
        }
        public async Task LoadRoute()
        {
            //var positionIndex = 1;
            var googleDirection = await googleMapsApi.GetDirections("18.5486875", "-70.2786714", "18.5525209", "-69.4376482");

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                CalculateRouteCommand.Execute(positions);

                //Location tracking simulation
                //Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                //{
                //    if (positions.Count > positionIndex)
                //    {
                //        UpdatePositionCommand.Execute(positions[positionIndex]);
                //        positionIndex++;
                //        return true;
                //    }
                //    else
                //    {
                //        return false;
                //    }
                //});
            }
        }
예제 #5
0
        public async Task LoadRoute()
        {
            var positionIndex   = 1;
            var googleDirection = await googleMapsApi.GetDirections(_originLatitud, _originLongitud, _destinationLatitud, _destinationLongitud);

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                CalculateRouteCommand.Execute(positions);

                HasRouteRunning = true;

                //Location tracking simulation
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                    if (positions.Count > positionIndex && HasRouteRunning)
                    {
                        UpdatePositionCommand.Execute(positions[positionIndex]);
                        positionIndex++;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
            }
            else
            {
                await App.Current.MainPage.DisplayAlert(":(", "No route found", "Ok");
            }
        }
        public async Task LoadRoute(string originLat, string originLng, string endLat, string endLng)
        {
            //endLat = "28.644800";
            //endLng = "77.216721";
            try
            {
                var googleDirection = await new GoogleMapsApiService().GetDirections(originLat, originLng, endLat, endLng);
                if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
                {
                    var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                    var polyline  = new Polyline();
                    polyline.StrokeColor = Color.Blue;
                    polyline.StrokeWidth = 5f;

                    foreach (var item in positions)
                    {
                        polyline.Positions.Add(new Position(item.Latitude, item.Longitude));
                    }
                    map.Polylines.Add(polyline);
                    return;
                }
            }
            catch (Exception ex)
            {
                //
            }
            await MaterialDialog.Instance.AlertAsync("No Suitable path exist !");
        }
예제 #7
0
        //InitPins() should be called before this method, _waypoints is added in InitPins()
        //A method that let's google handle the directions, shortest path etc.
        private async void MapDirections(string message = "")
        {
            //for diagnostic
            numberOfAPICalls++;
            Console.WriteLine($"{message} Number Of API Calls: #{numberOfAPICalls}");

            map.Polylines.Clear();
            if (_currentLocation == null)
            {
                _currentLocation = await Geolocation.GetLastKnownLocationAsync();
            }
            Position lastKnownPosition = new Position(_currentLocation.Latitude, _currentLocation.Longitude);

            if (_waypoints.Count > 0 && App.CheckIfInternet())
            {
                _invoicesCollection.Clear();
                _direction = await GoogleMapsAPI.MapDirectionsWithWaypoints(lastKnownPosition, _waypoints.ToArray());

                //Only create a line if it returns something from google
                if (_direction.Status != "ZERO_RESULTS" && _direction.Routes.Count > 0)
                {
                    List <Position> directionPolylines = PolylineHelper.Decode(_direction.Routes[0].OverviewPolyline.Points).ToList();

                    CreatePolylinesOnMap(directionPolylines);

                    foreach (int order in GoogleMapsAPI._waypointsOrder)
                    {
                        _invoicesCollection.Add(_invoices[order]);
                    }

                    DeliveryItemView.ItemsSource = _invoicesCollection;
                }
                else
                {
                    await DisplayAlert("Oops", "Unable to map the directions, please try to use internet connections or restart the app", "OK");
                }
            }
            else if (_waypoints.Count() == 0 && App.CheckIfInternet())
            {
                _direction = await GoogleMapsAPI.MapDirectionsNoWaypoints(lastKnownPosition);

                if (_direction.Status != "ZERO_RESULTS" && _direction.Routes.Count > 0)
                {
                    List <Position> directionPolylines = PolylineHelper.Decode(_direction.Routes[0].OverviewPolyline.Points).ToList();
                    CreatePolylinesOnMap(directionPolylines);
                }
            }
        }
예제 #8
0
        public async Task LoadRoute()
        {
            var positionIndex = 1;

            var googleDirection = await googleMapsApi.GetDirections(_originLatitud.Replace(",", "."),
                                                                    _originLongitud.Replace(",", "."),
                                                                    _destinationLatitud.Replace(",", "."),
                                                                    _destinationLongitud.Replace(",", "."));


            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                CalculateRouteCommand.Execute(positions);

                HasRouteRunning = true;

                MyMapa = true;

                var tempo = googleDirection.Routes[0].Legs[0].Duration.Text;


                var kms = googleDirection.Routes[0].Legs[0].Distance.Text;

                MyKms   = kms;
                MyTempo = tempo;

                //Location tracking simulation
                //Device.StartTimer(TimeSpan.FromSeconds(1),() =>
                //{
                //    if(positions.Count>positionIndex && HasRouteRunning)
                //    {
                //    UpdatePositionCommand.Execute(positions[positionIndex]);
                //        positionIndex++;
                //        return true;
                //    }
                //    else
                //    {
                //        return false;
                //    }
                //});
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert(":(", "No route found", "Ok");
            }
        }
        public async Task LoadRoute()
        {
            if (OriginCoordinates == null)
            {
                return;
            }

            ChangePageStatusCommand.Execute(PageStatusEnum.ShowingRoute);

            var googleDirection = await googleMapsApi.GetDirections($"{OriginCoordinates.Latitude}", $"{OriginCoordinates.Longitude}", $"{DestinationCoordinates.Latitude}", $"{DestinationCoordinates.Longitude}");

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                DrawRouteCommand.Execute(positions);
            }
            else
            {
                ChangePageStatusCommand.Execute(PageStatusEnum.Default);
                await UserDialogs.Instance.AlertAsync(":(", "No route found", "Ok");
            }
        }
예제 #10
0
        async void DrawRoute(Position start, Position end)
        {
            GoogleDirection googleDirection = await googleMapsApi.GetDirections(start.Latitude + "", start.Longitude + "",
                                                                                end.Latitude + "", end.Longitude + "");

            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                map.Polylines.Clear();
                var polyline = new Xamarin.Forms.GoogleMaps.Polyline();
                polyline.StrokeColor = Color.Black;
                polyline.StrokeWidth = 3;
                foreach (var p in positions)
                {
                    polyline.Positions.Add(p);
                }
                map.Polylines.Add(polyline);
                map.MoveToRegion(MapSpan.FromBounds(new Xamarin.Forms.GoogleMaps.Bounds(new Position(polyline.Positions[0].Latitude,
                                                                                                     polyline.Positions[0].Longitude - 0.008), new Position(polyline.Positions[polyline.Positions.Count - 1].Latitude,
                                                                                                                                                            polyline.Positions[polyline.Positions.Count - 1].Longitude + 0.008))), true);
            }
        }
예제 #11
0
        public async Task LoadRoute()
        {
            var googleDirection = await googleMapsApi.GetDirections(_originLatitud, _originLongitud, _destinationLatitud, _destinationLongitud);

            /* For Displaying Request and Response on Screen */
            await App.Current.MainPage.DisplayAlert("GoogleDirection", "https://maps.googleapis.com/maps/" + Constants.jsoncallstring, "OK");

            await App.Current.MainPage.DisplayAlert("GoogleDirection", Constants.jsonstring, "OK");

            Constants.jsoncallstring = "";
            Constants.jsonstring     = "";
            if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
            {
                CurrentGoogleDirection = googleDirection;
                var positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Routes.First().OverviewPolyline.Points)));
                CalculateRouteCommand.Execute(positions);

                HasRouteRunning = true;
            }
            else
            {
                await App.Current.MainPage.DisplayAlert(":(", "No route found", "Ok");
            }
        }
예제 #12
0
        public List <Position> TracarRota(string latOrigem, string lonOrigem, string latDestino, string lonDestino)
        {
            var             positionIndex   = 1;
            var             googleDirection = googleMapsApi.GetDirections(latOrigem, lonOrigem, latDestino, lonDestino);
            List <Position> positions       = new List <Position>();

            if (googleDirection.Result.Routes != null && googleDirection.Result.Routes.Count > 0)
            {
                positions = (Enumerable.ToList(PolylineHelper.Decode(googleDirection.Result.Routes.First().OverviewPolyline.Points)));

                //CalculateRouteCommand.Execute(positions);

                //HasRouteRunning = true;

                ////Location tracking simulation
                //Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                //{
                //    if (positions.Count > positionIndex && HasRouteRunning)
                //    {
                //        UpdatePositionCommand.Execute(positions[positionIndex]);
                //        positionIndex++;
                //        return true;
                //    }
                //    else
                //    {
                //        return false;
                //    }
                //});
            }
            else
            {
                App.Current.MainPage.DisplayAlert(":(", "No route found", "Ok");
            }

            return(positions);
        }