/// <summary> /// Create URI for quering /// </summary> /// <returns></returns> public override Uri ToUri() { var qsb = new Internal.QueryStringBuilder() .Append("origins", WaypointsToUri(_waypointsOrigin)) .Append("destinations", WaypointsToUri(_waypointsDestination)) .Append("mode", Mode.ToString()) .Append("language", Language) .Append("units", Units.ToString()) .Append("avoid", AvoidHelper.MakeAvoidString(Avoid)) .Append("departure_time", DepartureTime.ToString()); if (DepartureTime == null) { qsb.Append("arrival_time", ArrivalTime.ToString()); } if (DepartureTime != null && Mode.Equals(TravelMode.driving)) { qsb.Append("traffic_model ", TrafficModel.ToString()); } if (Mode.Equals(TravelMode.transit)) { qsb.Append("transit_mode", TransitMode.ToString()); qsb.Append("transit_routing_preference ", TransitRoutingPreference.ToString()); } var url = "json?" + qsb.ToString(); return(new Uri(url, UriKind.Relative)); }
protected override QueryStringParametersList GetQueryStringParameters() { if (Origins == null || !Origins.Any()) { throw new ArgumentException("Must specify an Origins"); } if (Destinations == null || !Destinations.Any()) { throw new ArgumentException("Must specify a Destinations"); } if (DepartureTime != null && ArrivalTime != null) { throw new ArgumentException("Must not specify both an ArrivalTime and a DepartureTime"); } if (Mode != DistanceMatrixTravelModes.transit && ArrivalTime != null) { throw new ArgumentException("Must not specify ArrivalTime for modes other than Transit"); } if (Mode != DistanceMatrixTravelModes.transit && TransitRoutingPreference != null) { throw new ArgumentException("Must not specify TransitRoutingPreference for modes other than Transit"); } if (Mode != DistanceMatrixTravelModes.transit && TransitModes != null && TransitModes.Length > 0) { throw new ArgumentException("Must not specify TransitModes for modes other than Transit"); } if ((!(Mode == null || Mode == DistanceMatrixTravelModes.driving) || DepartureTime == null) && TrafficModel != null) { throw new ArgumentException("A TrafficModel must not be specified unless the Mode is Driving and a DepartureTime is provided"); } var parameters = base.GetQueryStringParameters(); parameters.Add("origins", string.Join("|", Origins)); parameters.Add("destinations", string.Join("|", Destinations)); if (DepartureTime != null) { parameters.Add("departure_time", DepartureTime.ToString()); } if (ArrivalTime != null) { parameters.Add("arrival_time", ArrivalTime.ToString()); } if (Mode != null) { parameters.Add("mode", Mode.ToString()); } if (TrafficModel != null) { parameters.Add("traffic_model", TrafficModel.ToString()); } if (TransitRoutingPreference != null) { parameters.Add("transit_routing_preference", TransitRoutingPreference.ToString()); } if (TransitModes != null && TransitModes.Length > 0) { parameters.Add("transit_mode", string.Join("|", TransitModes.Select(a => a.ToString()))); } if (Avoid != null) { parameters.Add("avoid", Avoid.ToString()); } if (Units != null) { parameters.Add("units", Units.ToString()); } if (!string.IsNullOrWhiteSpace(Language)) { parameters.Add("language", Language); } return(parameters); }