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); } }); } }
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() { 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; } }); } }
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"); } }
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); }
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"); } }
private async void DrawRoute() { SetOneDirection(); if (Start != null && End != null && Start != End) { Device.BeginInvokeOnMainThread(() => IsBusyOnMap = true); //IsBusy = true; var direction = await googleMapsApi.GetDirections( Start.StringLat(), Start.StringLng(), End.StringLat(), End.StringLng()); if (direction.Success) { plottedRoutes.Clear(); Map.Polylines.Clear(); ShowMeMyCameraUpdate(direction.Routes[0].Bounds); Leg[] legs = null; for (int index = 0; index < direction.Routes.Length; index++) { var route = direction.Routes[index]; legs = direction.Routes[0].Legs; Polyline polyLineData = new Polyline { StrokeWidth = 5, StrokeColor = Color.FromRgb(118, 170, 219) }; foreach (var coord in route.OverviewPolylineCoords) { polyLineData.Positions.Add(new Position(coord.Lat, coord.Lng)); } Map.Polylines.Add(polyLineData); plottedRoutes.Add(polyLineData); } //FOR DISTANCE ServiceInfo(legs[0]); } Device.BeginInvokeOnMainThread(() => IsBusyOnMap = false); //IsBusy = false; } ; }
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"); } }
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); } }