/// <summary> /// Gets a POST body for a snap to road request. /// </summary> /// <returns>A POST body for a snap to road request.</returns> private string GetPostRequestBody() { var sb = new StringBuilder(); sb.Append("{"); sb.Append("\"points\":["); foreach (var p in Points) { sb.AppendFormat(CultureInfo.InvariantCulture, "{{\"latitude\":{0:0.#####},\"longitude\":{1:0.#####}}},", p.Latitude, p.Longitude); } //Remove trailing comma. sb.Length--; sb.Append("]"); if (Interpolate) { sb.Append(",\"interpolate\":true"); } if (IncludeSpeedLimit) { sb.Append(",\"includeSpeedLimit\":true"); } if (IncludeTruckSpeedLimit) { sb.Append(",\"includeTruckSpeedLimit\":true"); } sb.AppendFormat(",\"speedUnit\":\"{0}\"", Enum.GetName(typeof(SpeedUnitType), SpeedUnit)); //TODO: Truck mode is not supported, so fall back to driving. Remove this if truck routing support added. //Note, difference between snapping car vs truck should be minor since the truck GPS points should only be on roads it is meant to be on. if (TravelMode == TravelModeType.Truck) { TravelMode = TravelModeType.Driving; } sb.AppendFormat(",\"travelMode\":\"{0}\"", Enum.GetName(typeof(TravelModeType), TravelMode)); sb.Append("}"); return(sb.ToString()); }
/// <summary> /// Defines the method of travel. /// Options are driving, walking (which prefers pedestrian paths and sidewalks, where available), bicycling (which routes via bike paths and preferred streets where available), or transit. /// If no travel mode is specified, the Google Map shows one or more of the most relevant modes for the specified route and/or user preferences. /// </summary> /// <param name="travelMode">The method of travel.</param> /// <returns>The same <see cref="DirectionsParams"/> instance.</returns> public DirectionsParams SetTravelMode(TravelModeType travelMode) { TravelMode = travelMode; return(this); }