Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DurationInTraffic #157

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Google.Maps/Direction/DirectionLeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class DirectionLeg

[JsonProperty("duration")]
public ValueText Duration { get; set; }

[JsonProperty("duration_in_traffic")]
public ValueText DurationInTraffic { get; set; }

[JsonProperty("distance")]
public ValueText Distance { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions src/Google.Maps/Direction/DirectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public class DirectionRequest : BaseRequest
[DefaultValue(TravelMode.driving)]
public TravelMode Mode { get; set; }


/// <summary>
/// Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration_in_traffic field in the response,
/// which contains the predicted time in traffic based on historical averages. The traffic_model parameter may only be specified for driving directions where
/// the request includes a departure_time, and only if the request includes an API key or a Google Maps Platform Premium Plan client ID.
/// </summary>
[DefaultValue(TrafficModel.best_guess)]
public TrafficModel TrafficModel { get; set; }

/// <summary>
/// (optional) Directions may be calculated that adhere to certain restrictions.
/// </summary>
Expand Down Expand Up @@ -119,6 +128,7 @@ public override Uri ToUri()
.Append("origin", (Origin == null ? (string)null : Origin.GetAsUrlParameter()))
.Append("destination", (Destination == null ? (string)null : Destination.GetAsUrlParameter()))
.Append("mode", (Mode != TravelMode.driving ? Mode.ToString() : (string)null))
.Append("traffic_model", (TrafficModel!=TrafficModel.best_guess ? TrafficModel.ToString():(string)null))
.Append("departure_time", (DepartureTime == null ? null : DepartureTime.Value.ToString()))
.Append("arrival_time", (ArrivalTime == null ? null : ArrivalTime.Value.ToString()))
.Append("waypoints", WaypointsToUri())
Expand Down
7 changes: 2 additions & 5 deletions src/Google.Maps/Google.Maps.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netstandard1.3</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately this change makes it much harder to approve the pull request. I would consider changing the targetframework to be considered out of scope of adding traffic_model to the request.

<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
Expand All @@ -10,9 +10,6 @@
<DefineConstants>HAS_SYSTEMDRAWING</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions src/Google.Maps/TrafficModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Google.Maps {
/// <summary>
/// Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration_in_traffic field in the response,
/// which contains the predicted time in traffic based on historical averages. The traffic_model parameter may only be specified for driving directions where
/// the request includes a departure_time, and only if the request includes an API key or a Google Maps Platform Premium Plan client ID.
/// </summary>
/// <see href="http://code.google.com/apis/maps/documentation/directions/#traffic_model"/>
public enum TrafficModel {
/// <summary>
/// (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given what is known about both historical
/// traffic conditions and live traffic. Live traffic becomes more important the closer the departure_time is to now.
/// </summary>
best_guess,

/// <summary>
/// indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value
/// </summary>
pessimistic,

/// <summary>
/// indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value.
/// </summary>
optimistic,

}
}