Skip to content

Commit

Permalink
Merge pull request #159 from cbalokanmeme/master
Browse files Browse the repository at this point in the history
Update DistanceMatrix request
  • Loading branch information
ericnewton76 committed Feb 15, 2022
2 parents f3e6fe9 + 51917b3 commit 75b0064
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
53 changes: 51 additions & 2 deletions src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DistanceMatrixRequest : BaseRequest

/// <summary>
/// (optional) Specifies the unit system to use when expressing distance as text.
/// <see href="http://code.google.com/intl/it-IT/apis/maps/documentation/distancematrix/#unit_systems"/>
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro#unit_systems"/>
/// </summary>
public Units Units { get; set; }

Expand All @@ -52,6 +52,42 @@ public class DistanceMatrixRequest : BaseRequest
/// </summary>
public string Language { get; set; }

/// <summary>
/// (optional) Specifies the desired time of arrival for transit requests, in seconds since midnight, January 1, 1970 UTC.
/// You can specify either departure_time or arrival_time, but not both.
/// Note that arrival_time must be specified as an integer.
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
/// </summary>
public int? DepartureTime { get; set; }

/// <summary>
/// (optional) The desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC.
/// Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second).
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
/// </summary>
public int? ArrivalTime { get; set; }

/// <summary>
/// (optional) 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 requests where the travel mode is driving, and 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
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
/// </summary>
public TrafficModels TrafficModel { get; set; }

/// <summary>
/// (optional) Specifies one or more preferred modes of transit. This parameter may only be specified for requests where the mode is transit
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
/// </summary>
public TransitModes TransitMode { get; set; }

/// <summary>
/// (optional) Specifies preferences for transit requests. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API.
/// This parameter may only be specified for requests where the mode is transit.
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
/// </summary>
public TransitRoutingPreferences TransitRoutingPreference { get; set; }

/// <summary>
/// List of origin waypoints
/// </summary>
Expand Down Expand Up @@ -158,7 +194,20 @@ public override Uri ToUri()
.Append("mode", Mode.ToString())
.Append("language", Language)
.Append("units", Units.ToString())
.Append("avoid", AvoidHelper.MakeAvoidString(Avoid));
.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();

Expand Down
7 changes: 7 additions & 0 deletions src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public class DistanceMatrixElement

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

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

[JsonProperty("fare")]
public FareValueText fare { get; set; }

}//end class
}//end class
}//end namespace
29 changes: 29 additions & 0 deletions src/Google.Maps/TrafficModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

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 requests where the travel mode is driving, and 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>
[Flags]
public enum TrafficModels
{
/// <summary>
///
/// </summary>
best_guess = 0,

/// <summary>
///
/// </summary>
pessimistic = 1,

/// <summary>
///
/// </summary>
optimistic = 2,

}
}
35 changes: 35 additions & 0 deletions src/Google.Maps/TransitModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

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 requests where the travel mode is driving, and 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>
[Flags]
public enum TransitModes
{
/// <summary>
/// indicates that the calculated route should prefer travel by bus.
/// </summary>
bus = 0,
/// <summary>
/// indicates that the calculated route should prefer travel by subway.
/// </summary>
subway = 1,
/// <summary>
/// indicates that the calculated route should prefer travel by train.
/// </summary>
train = 2,
/// <summary>
/// indicates that the calculated route should prefer travel by tram and light rail.
/// </summary>
tram = 3,
/// <summary>
/// indicates that the calculated route should prefer travel by train, tram, light rail, and subway. This is equivalent to transit_mode = train | tram | subway.
/// </summary>
rail = 4

}
}
23 changes: 23 additions & 0 deletions src/Google.Maps/TransitRoutingPreferences.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

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 requests where the travel mode is driving, and 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>
[Flags]
public enum TransitRoutingPreferences
{
/// <summary>
/// indicates that the calculated route should prefer limited amounts of walking.
/// </summary>
less_walking = 0,
/// <summary>
/// indicates that the calculated route should prefer a limited number of transfers.
/// </summary>
fewer_transfers = 1,

}
}
8 changes: 6 additions & 2 deletions src/Google.Maps/ValueText.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Google.Maps
Expand All @@ -19,4 +17,10 @@ public override string ToString()
return String.Format("{0} ({1})", Text, Value);
}
}

public class FareValueText: ValueText
{
[JsonProperty("currency")]
public string Currency { get; set; }
}
}

0 comments on commit 75b0064

Please sign in to comment.