public override string GetRequestUrl() { string pointStr = string.Format("LocationRecog/{0}?", CenterPoint.ToString()); string du; List <string> param_list = new List <string> { string.Format("r={0}", Radius.ToString(System.Globalization.CultureInfo.InvariantCulture)), string.Format("top={0}", Top.ToString()), string.Format("distanceUnit={0}", EnumHelper.DistanceUnitTypeToString(DistanceUnits)), string.Format("verboseplacenames={0}", VerbosePlaceNames.ToString().ToLower()), string.Format("key={0}", BingMapsKey.ToString()), string.Format("includeEntityTypes={0}", IncludeEntityTypes) }; if (DateTimeInput.HasValue) { param_list.Add(string.Format("dateTime={0}", DateTimeHelper.GetUTCString(DateTimeInput.Value))); } return(this.Domain + pointStr + string.Join("&", param_list)); }
/// <summary> /// Gets the request URL to perform a query for an isochrone. /// </summary> /// <returns>A request URL to perform a query for an isochron.</returns> public override string GetRequestUrl() { var sb = new StringBuilder(this.Domain); sb.Append("Routes/IsochronesAsync"); //Truck mode is not supported, so fall back to driving. if (TravelMode == TravelModeType.Truck) { TravelMode = TravelModeType.Driving; } sb.AppendFormat("?travelMode={0}", Enum.GetName(typeof(TravelModeType), TravelMode)); if (Waypoint == null) { throw new Exception("A waypoint must be specified."); } if (Waypoint.Coordinate != null) { sb.AppendFormat(CultureInfo.InvariantCulture, "&waypoint={0:0.#####},{1:0.#####}", Waypoint.Coordinate.Latitude, Waypoint.Coordinate.Longitude); } else if (!String.IsNullOrWhiteSpace(Waypoint.Address)) { sb.AppendFormat("&waypoint={0}", Waypoint.Address); } else { throw new Exception("Invalid waypoint: A coordinate or address must be specified."); } if (MaxTime > 0) { if (TimeUnit == TimeUnitType.Second && MaxTime > 3600) { throw new Exception("MaxTime value must be <= 3600 seconds."); } else if (TimeUnit == TimeUnitType.Minute && MaxTime > 60) { throw new Exception("MaxTime value must be <= 60 minutes."); } sb.AppendFormat("&maxTime={0}&timeUnit={1}", MaxTime, Enum.GetName(typeof(TimeUnitType), TimeUnit)); if (TravelMode != TravelModeType.Walking && DateTime != null && DateTime.HasValue) { sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, "&dt={0:G}", DateTime.Value); } //Can only optimize based on time or time with traffic when generating time based isochrones. if (Optimize != RouteOptimizationType.Time && Optimize != RouteOptimizationType.TimeWithTraffic) { Optimize = RouteOptimizationType.Time; } } else if (MaxDistance > 0) { if (TravelMode == TravelModeType.Transit) { throw new Exception("Distance based isochrones are not supported for transit travel mode. Use maxTime."); } sb.AppendFormat("&maxDistance={0}&distanceUnit={1}", MaxDistance, EnumHelper.DistanceUnitTypeToString(DistanceUnit)); //Can only optimize based on distance when generating distance based isochrones. if (Optimize != RouteOptimizationType.Distance) { Optimize = RouteOptimizationType.Distance; } } else { throw new Exception("A max time or distance must be specified."); } sb.AppendFormat("&optimize={0}", Enum.GetName(typeof(RouteOptimizationType), Optimize)); //TODO: uncomment when/if avoid is supported. //if (TravelMode == TravelModeType.Driving) //{ // if (Avoid != null && Avoid.Count > 0) // { // sb.Append("&avoid="); // for (var i = 0; i < Avoid.Count; i++) // { // sb.Append(Enum.GetName(typeof(AvoidType), Avoid[i])); // if (i < Avoid.Count - 1) // { // sb.Append(","); // } // } // } //} sb.Append(GetBaseRequestUrl()); return(sb.ToString()); }
public override string GetRequestUrl() { if (Waypoint == null || (Waypoint.Coordinate == null && string.IsNullOrWhiteSpace(Waypoint.Address))) { throw new Exception("A waypoiny must be specified."); } if (Types == null || Types.Count == 0) { throw new Exception("One or more types must be specified."); } //Truck mode is not supported, so fall back to driving. if (TravelMode == TravelModeType.Truck) { TravelMode = TravelModeType.Driving; } var sb = new StringBuilder(this.Domain); sb.AppendFormat("Routes/LocalInsightsAsync?travelMode={0}", Enum.GetName(typeof(TravelModeType), TravelMode)); if (Waypoint.Coordinate != null) { sb.AppendFormat("&waypoint={0}", Waypoint.Coordinate.ToString()); } else if (!string.IsNullOrWhiteSpace(Waypoint.Address)) { sb.AppendFormat("&waypoint={0}", string.Join(",", Waypoint.Address)); } if (MaxTime > 0) { if (TimeUnit == TimeUnitType.Second && MaxTime > 3600) { throw new Exception("MaxTime value must be <= 3600 seconds."); } else if (TimeUnit == TimeUnitType.Minute && MaxTime > 60) { throw new Exception("MaxTime value must be <= 60 minutes."); } sb.AppendFormat("&maxTime={0}&timeUnit={1}", MaxTime, Enum.GetName(typeof(TimeUnitType), TimeUnit)); if (TravelMode != TravelModeType.Walking && DateTime != null && DateTime.HasValue) { sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, "&dt={0:G}", DateTime.Value); } //Can only optimize based on time or time with traffic when generating time based isochrones. if (Optimize != RouteOptimizationType.Time && Optimize != RouteOptimizationType.TimeWithTraffic) { Optimize = RouteOptimizationType.Time; } } else if (MaxDistance > 0) { if (TravelMode == TravelModeType.Transit) { throw new Exception("Distance based isochrones are not supported for transit travel mode. Use maxTime."); } sb.AppendFormat(CultureInfo.InvariantCulture, "&maxDistance={0}&distanceUnit={1}", MaxDistance, EnumHelper.DistanceUnitTypeToString(DistanceUnit)); //Can only optimize based on distance when generating distance based isochrones. if (Optimize != RouteOptimizationType.Distance) { Optimize = RouteOptimizationType.Distance; } } else { throw new Exception("A max time or distance must be specified."); } sb.AppendFormat("&optimize={0}", Enum.GetName(typeof(RouteOptimizationType), Optimize)); sb.AppendFormat("&type={0}", string.Join(",", Types)); sb.Append(GetBaseRequestUrl()); return(sb.ToString()); }