Example #1
0
        /// <summary>
        /// Sets the route calculation data
        /// </summary>
        /// <param name="route">The PCL route</param>
        /// <param name="routeResult">The route api result</param>
        private void SetRouteData(TKRoute route, MapRoute routeResult)
        {
            var latLngBounds = routeResult.BoundingBox;

            var apiSteps       = routeResult.Legs.First().Maneuvers;
            var steps          = new TKRouteStep[apiSteps.Count];
            var routeFunctions = (IRouteFunctions)route;

            for (int i = 0; i < steps.Length; i++)
            {
                steps[i] = new TKRouteStep();
                var stepFunctions = (IRouteStepFunctions)steps[i];
                var apiStep       = apiSteps.ElementAt(i);

                stepFunctions.SetDistance(apiStep.LengthInMeters);
                stepFunctions.SetInstructions(apiStep.InstructionText);
            }
            routeFunctions.SetSteps(steps);
            routeFunctions.SetDistance(routeResult.Legs.First().LengthInMeters);
            routeFunctions.SetTravelTime(routeResult.Legs.First().EstimatedDuration.TotalMinutes);

            routeFunctions.SetBounds(
                MapSpan.FromCenterAndRadius(
                    latLngBounds.Center.ToPosition(),
                    Distance.FromKilometers(
                        new Position(latLngBounds.SoutheastCorner.Latitude, latLngBounds.SoutheastCorner.Longitude)
                        .DistanceTo(
                            new Position(latLngBounds.NorthwestCorner.Latitude, latLngBounds.NorthwestCorner.Longitude)) / 2)));

            routeFunctions.SetIsCalculated(true);
        }
Example #2
0
        /// <summary>
        /// Sets the route calculation data
        /// </summary>
        /// <param name="route">The PCL route</param>
        /// <param name="routeResult">The rourte api result</param>
        private void SetRouteData(TKRoute route, GmsRouteResult routeResult)
        {
            var latLngBounds = new LatLngBounds(
                new LatLng(routeResult.Bounds.SouthWest.Latitude, routeResult.Bounds.SouthWest.Longitude),
                new LatLng(routeResult.Bounds.NorthEast.Latitude, routeResult.Bounds.NorthEast.Longitude));

            var apiSteps       = routeResult.Legs.First().Steps;
            var steps          = new TKRouteStep[apiSteps.Count()];
            var routeFunctions = (IRouteFunctions)route;


            for (int i = 0; i < steps.Length; i++)
            {
                steps[i] = new TKRouteStep();
                var stepFunctions = (IRouteStepFunctions)steps[i];
                var apiStep       = apiSteps.ElementAt(i);

                stepFunctions.SetDistance(apiStep.Distance.Value);
                stepFunctions.SetInstructions(apiStep.HtmlInstructions);
            }
            routeFunctions.SetSteps(steps);
            routeFunctions.SetDistance(routeResult.Legs.First().Distance.Value);
            routeFunctions.SetTravelTime(routeResult.Legs.First().Duration.Value);

            routeFunctions.SetBounds(
                MapSpan.FromCenterAndRadius(
                    latLngBounds.Center.ToPosition(),
                    Distance.FromKilometers(
                        new Position(latLngBounds.Southwest.Latitude, latLngBounds.Southwest.Longitude)
                        .DistanceTo(
                            new Position(latLngBounds.Northeast.Latitude, latLngBounds.Northeast.Longitude)) / 2)));
            routeFunctions.SetIsCalculated(true);
        }