Skip to content

Commit 75b0064

Browse files
authored
Merge pull request #159 from cbalokanmeme/master
Update DistanceMatrix request
2 parents f3e6fe9 + 51917b3 commit 75b0064

6 files changed

+151
-4
lines changed

src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs

+51-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class DistanceMatrixRequest : BaseRequest
4242

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

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

55+
/// <summary>
56+
/// (optional) Specifies the desired time of arrival for transit requests, in seconds since midnight, January 1, 1970 UTC.
57+
/// You can specify either departure_time or arrival_time, but not both.
58+
/// Note that arrival_time must be specified as an integer.
59+
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
60+
/// </summary>
61+
public int? DepartureTime { get; set; }
62+
63+
/// <summary>
64+
/// (optional) The desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC.
65+
/// Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second).
66+
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
67+
/// </summary>
68+
public int? ArrivalTime { get; set; }
69+
70+
/// <summary>
71+
/// (optional) Specifies the assumptions to use when calculating time in traffic.
72+
/// 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.
73+
/// 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
74+
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
75+
/// </summary>
76+
public TrafficModels TrafficModel { get; set; }
77+
78+
/// <summary>
79+
/// (optional) Specifies one or more preferred modes of transit. This parameter may only be specified for requests where the mode is transit
80+
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
81+
/// </summary>
82+
public TransitModes TransitMode { get; set; }
83+
84+
/// <summary>
85+
/// (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.
86+
/// This parameter may only be specified for requests where the mode is transit.
87+
/// <see href="https://developers.google.com/maps/documentation/distance-matrix/intro" />
88+
/// </summary>
89+
public TransitRoutingPreferences TransitRoutingPreference { get; set; }
90+
5591
/// <summary>
5692
/// List of origin waypoints
5793
/// </summary>
@@ -158,7 +194,20 @@ public override Uri ToUri()
158194
.Append("mode", Mode.ToString())
159195
.Append("language", Language)
160196
.Append("units", Units.ToString())
161-
.Append("avoid", AvoidHelper.MakeAvoidString(Avoid));
197+
.Append("avoid", AvoidHelper.MakeAvoidString(Avoid))
198+
.Append("departure_time", DepartureTime.ToString());
199+
200+
if(DepartureTime == null)
201+
qsb.Append("arrival_time", ArrivalTime.ToString());
202+
203+
if (DepartureTime != null && Mode.Equals(TravelMode.driving))
204+
qsb.Append("traffic_model ", TrafficModel.ToString());
205+
206+
if (Mode.Equals(TravelMode.transit))
207+
{
208+
qsb.Append("transit_mode", TransitMode.ToString());
209+
qsb.Append("transit_routing_preference ", TransitRoutingPreference.ToString());
210+
}
162211

163212
var url = "json?" + qsb.ToString();
164213

src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public class DistanceMatrixElement
5757

5858
[JsonProperty("duration")]
5959
public ValueText duration { get; set; }
60+
61+
[JsonProperty("duration_in_traffic")]
62+
public ValueText duration_in_traffic { get; set; }
63+
64+
[JsonProperty("fare")]
65+
public FareValueText fare { get; set; }
66+
6067
}//end class
6168
}//end class
6269
}//end namespace

src/Google.Maps/TrafficModels.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace Google.Maps
4+
{
5+
/// <summary>
6+
/// Specifies the assumptions to use when calculating time in traffic.
7+
/// 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.
8+
/// 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.
9+
/// </summary>
10+
[Flags]
11+
public enum TrafficModels
12+
{
13+
/// <summary>
14+
///
15+
/// </summary>
16+
best_guess = 0,
17+
18+
/// <summary>
19+
///
20+
/// </summary>
21+
pessimistic = 1,
22+
23+
/// <summary>
24+
///
25+
/// </summary>
26+
optimistic = 2,
27+
28+
}
29+
}

src/Google.Maps/TransitModes.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
namespace Google.Maps
4+
{
5+
/// <summary>
6+
/// Specifies the assumptions to use when calculating time in traffic.
7+
/// 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.
8+
/// 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.
9+
/// </summary>
10+
[Flags]
11+
public enum TransitModes
12+
{
13+
/// <summary>
14+
/// indicates that the calculated route should prefer travel by bus.
15+
/// </summary>
16+
bus = 0,
17+
/// <summary>
18+
/// indicates that the calculated route should prefer travel by subway.
19+
/// </summary>
20+
subway = 1,
21+
/// <summary>
22+
/// indicates that the calculated route should prefer travel by train.
23+
/// </summary>
24+
train = 2,
25+
/// <summary>
26+
/// indicates that the calculated route should prefer travel by tram and light rail.
27+
/// </summary>
28+
tram = 3,
29+
/// <summary>
30+
/// indicates that the calculated route should prefer travel by train, tram, light rail, and subway. This is equivalent to transit_mode = train | tram | subway.
31+
/// </summary>
32+
rail = 4
33+
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace Google.Maps
4+
{
5+
/// <summary>
6+
/// Specifies the assumptions to use when calculating time in traffic.
7+
/// 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.
8+
/// 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.
9+
/// </summary>
10+
[Flags]
11+
public enum TransitRoutingPreferences
12+
{
13+
/// <summary>
14+
/// indicates that the calculated route should prefer limited amounts of walking.
15+
/// </summary>
16+
less_walking = 0,
17+
/// <summary>
18+
/// indicates that the calculated route should prefer a limited number of transfers.
19+
/// </summary>
20+
fewer_transfers = 1,
21+
22+
}
23+
}

src/Google.Maps/ValueText.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using Newtonsoft.Json;
53

64
namespace Google.Maps
@@ -19,4 +17,10 @@ public override string ToString()
1917
return String.Format("{0} ({1})", Text, Value);
2018
}
2119
}
20+
21+
public class FareValueText: ValueText
22+
{
23+
[JsonProperty("currency")]
24+
public string Currency { get; set; }
25+
}
2226
}

0 commit comments

Comments
 (0)