private string GetRequestUrl()

in Source/Requests/RouteRequest.cs [330:399]


        private string GetRequestUrl(int startIdx, out int endIdx)
        {
            endIdx = Waypoints.Count;

            var sb = new StringBuilder(this.Domain);

            var TravelMode = (RouteOptions != null) ? RouteOptions.TravelMode : TravelModeType.Driving;

            if (TravelMode == TravelModeType.Truck)
            {
                sb.Append("Routes/TruckAsync?");
            }
            else
            {
                sb.AppendFormat("Routes/{0}?", Enum.GetName(typeof(TravelModeType), TravelMode));

                int wayCnt = 0, viaCnt = 0;

                for (int i = startIdx; i < Waypoints.Count; i++)
                {
                    if (Waypoints[i].IsViaPoint)
                    {
                        sb.AppendFormat("&vwp.{0}=", i - startIdx);
                        viaCnt++;

                        if (TravelMode == TravelModeType.Transit)
                        {
                            throw new Exception("ViaWaypoints not supported for Transit directions.");
                        }
                    }
                    else
                    {
                        sb.AppendFormat("&wp.{0}=", i - startIdx);

                        if (viaCnt > 10)
                        {
                            throw new Exception("More than 10 viaWaypoints between waypoints.");
                        }

                        wayCnt++;
                        viaCnt = 0;
                    }

                    if (Waypoints[i].Coordinate != null)
                    {
                        sb.AppendFormat(CultureInfo.InvariantCulture, "{0:0.#####},{1:0.#####}", Waypoints[i].Coordinate.Latitude, Waypoints[i].Coordinate.Longitude);
                    }
                    else
                    {
                        sb.AppendFormat("{0}", Uri.EscapeDataString(Waypoints[i].Address));
                    }

                    //Only allow up to the batchSize waypoints in a request.
                    if (wayCnt == batchSize)
                    {
                        endIdx = i;
                        break;
                    }
                }

                if (RouteOptions != null)
                {
                    sb.Append(RouteOptions.GetUrlParam(startIdx));
                }
            }

            sb.Append(GetBaseRequestUrl());

            return sb.ToString();
        }