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");
            }
        }
Exemplo n.º 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);
                    }
                });
            }
        }
Exemplo n.º 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;
                //    }
                //});
            }
        }
Exemplo n.º 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 !");
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 13
0
        private bool UpdateSketchGeometry(PathGeometry inputPath)
        {
            var flag = false;

            flag |= GeometryHelper.EnsureGeometryType(out var geometry, ref CachedGeometry,
                                                      () => new PathGeometry());
            flag |= geometry.Figures.EnsureListCount(inputPath.Figures.Count, () => new PathFigure());
            var random = new RandomEngine(_randomSeed);

            for (var i = 0; i < inputPath.Figures.Count; i++)
            {
                var pathFigure = inputPath.Figures[i];
                var isClosed   = pathFigure.IsClosed;
                var isFilled   = pathFigure.IsFilled;
                if (pathFigure.Segments.Count == 0)
                {
                    flag |= geometry.Figures[i]
                            .SetIfDifferent(PathFigure.StartPointProperty, pathFigure.StartPoint);
                    flag |= geometry.Figures[i].Segments.EnsureListCount(0);
                }
                else
                {
                    var list = new List <Point>(pathFigure.Segments.Count * 3);
                    foreach (var segment in GetEffectiveSegments(pathFigure))
                    {
                        var resultPolyline = new List <Point>
                        {
                            segment.Points[0]
                        };
                        segment.Flatten(resultPolyline, 0.0, null);
                        var polyline = new PolylineData(resultPolyline);
                        if (resultPolyline.Count > 1 && polyline.TotalLength > 4.0)
                        {
                            var a             = polyline.TotalLength / 8.0;
                            var sampleCount   = (int)Math.Max(2.0, Math.Ceiling(a));
                            var interval      = polyline.TotalLength / sampleCount;
                            var scale         = interval / 8.0;
                            var samplePoints  = new List <Point>(sampleCount);
                            var sampleNormals = new List <Vector>(sampleCount);
                            var sampleIndex   = 0;
                            PolylineHelper.PathMarch(polyline, 0.0, 0.0, delegate(MarchLocation location)
                            {
                                if (location.Reason == MarchStopReason.CompletePolyline)
                                {
                                    return(double.NaN);
                                }
                                if (location.Reason != MarchStopReason.CompleteStep)
                                {
                                    return(location.Remain);
                                }
                                if (sampleIndex++ == sampleCount)
                                {
                                    return(double.NaN);
                                }
                                samplePoints.Add(location.GetPoint(polyline.Points));
                                sampleNormals.Add(location.GetNormal(polyline));
                                return(interval);
                            });
                            DisturbPoints(random, scale, samplePoints, sampleNormals);
                            list.AddRange(samplePoints);
                        }
                        else
                        {
                            list.AddRange(resultPolyline);
                            list.RemoveLast();
                        }
                    }

                    if (!isClosed)
                    {
                        list.Add(pathFigure.Segments.Last().GetLastPoint());
                    }
                    flag |= PathFigureHelper.SyncPolylineFigure(geometry.Figures[i], list, isClosed,
                                                                isFilled);
                }
            }

            if (flag)
            {
                CachedGeometry = PathGeometryHelper.FixPathGeometryBoundary(CachedGeometry);
            }
            return(flag);
        }