Example #1
0
        public GDirectionResponse GetGRoute(GDirectionRequest request, bool alternatives)
        {
            var waypoints = "via:";
            var first     = true;

            if (request.WayPoints != null)
            {
                foreach (var point in request.WayPoints)
                {
                    if (!first)
                    {
                        waypoints += "|";
                    }
                    first      = false;
                    waypoints += point.Lat + "," + point.Lng;
                }
            }
            var directionResponse = new GDirectionResponse();
            var client            = new RestClient(directionApi);
            var restRequest       = new RestRequest("json", Method.GET);

            restRequest.AddParameter("origin", request.Src.Lat + "," + request.Src.Lng);
            restRequest.AddParameter("destination", request.Dst.Lat + "," + request.Dst.Lng);
            restRequest.AddParameter("mode", "driving");
            if (request.WayPoints != null && request.WayPoints.Count > 0)
            {
                restRequest.AddParameter("waypoints", waypoints);
                restRequest.AddParameter("waypoints", "optimize:true");
            }
            if (alternatives)
            {
                restRequest.AddParameter("alternatives", "true");
            }
            else
            {
                restRequest.AddParameter("alternatives", "false");
            }

            restRequest.AddParameter("language", "fa");
            IRestResponse        response = client.Execute(restRequest);
            JavaScriptSerializer js       = new JavaScriptSerializer();

            if (!string.IsNullOrWhiteSpace(response.Content))
            {
                directionResponse = js.Deserialize <GDirectionResponse>(response.Content);
            }
            return(directionResponse);
        }
Example #2
0
        public static List <CoreExternalService.Models.Point> GetPathStepsFromGService(GDirectionResponse gRoute)
        {
            var steps = new List <CoreExternalService.Models.Point>();

            CoreExternalService.Models.Point point;
            var IsFirst        = true;
            var firstOrDefault = gRoute.Routes.FirstOrDefault();

            if (firstOrDefault != null)
            {
                foreach (var leg in firstOrDefault.Legs)
                {
                    foreach (var step in leg.Steps)
                    {
                        if (IsFirst)
                        {
                            point          = new CoreExternalService.Models.Point();
                            point.Lat      = step.Start_location.Lat;
                            point.Lng      = step.Start_location.Lng;
                            point.Distance = step.Distance.Value.ToString();
                            point.Duration = step.Duration.Value.ToString();
                            IsFirst        = false;
                            steps.Add(point);
                        }
                        point          = new CoreExternalService.Models.Point();
                        point.Lat      = step.End_location.Lat;
                        point.Lng      = step.End_location.Lng;
                        point.Distance = step.Distance.Value.ToString();
                        point.Duration = step.Duration.Value.ToString();
                        steps.Add(point);
                    }
                }
            }
            return(steps);
        }