public override string GetRequestUrl()

in Source/Requests/DistanceMatrixRequest.cs [287:350]


        public override string GetRequestUrl()
        {
            //Matrix when using POST
            //https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?key=BingMapsKey

            ValidateLocations(Origins, "Origin");
            
            if (Destinations != null)
            {
                ValidateLocations(Destinations, "Destination");
            }

            bool isAsyncRequest = false;

            int numCoordPairs = GetNumberOfCoordinatePairs();

            if (numCoordPairs > MaxCoordinatePairs && TravelMode != TravelModeType.Truck)
            {
                throw new Exception("The number of Origins and Destinations provided would result in a matrix that has more than 625 coordinate pairs.");
            }

            if (StartTime.HasValue)
            {
                if(TravelMode != TravelModeType.Driving && TravelMode != TravelModeType.Truck)
                {
                    throw new Exception("Start time parameter can only be used with the driving or truck travel mode.");
                }

                //Since start time is specified, an asynchronous request will be made which allows up to 100 coordinate pairs in the matrix (coordinate pairs).
                if (numCoordPairs > MaxAsyncCoordinatePairsHistogram)
                {
                    throw new Exception("The number of Origins and Destinations provided would result in a matrix that has more than 100 coordinate pairs which is the limit when a histogram is requested.");
                }

                isAsyncRequest = true;
            }

            if (EndTime.HasValue)
            {
                if(!StartTime.HasValue)
                {
                    throw new Exception("End time specified without a corresponding start time.");
                }

                var timeSpan = EndTime.Value.Subtract(StartTime.Value);

                if(timeSpan.TotalHours > MaxTimeSpanHours)
                {
                    throw new Exception("The time span between start and end time is more than 24 hours.");
                }

                if(Resolution < 0 || Resolution > 4)
                {
                    throw new Exception("Invalid resolution specified. Should be 1, 2, 3, or 4.");
                }
            }
            
            if(TravelMode == TravelModeType.Truck)
            {
                return string.Empty;
            }

            return this.Domain + "Routes/DistanceMatrix" + ((isAsyncRequest)? "Async?" : "" + "?") + GetBaseRequestUrl();
        }