Skip to content

Commit

Permalink
Merge pull request #23 from frankhommers/master
Browse files Browse the repository at this point in the history
Enhanced Avoid and added Available
  • Loading branch information
Richard Thombs committed Sep 10, 2014
2 parents 5df7d79 + e48a99b commit 207dccd
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 28 deletions.
34 changes: 34 additions & 0 deletions src/Google.Maps/Avoid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace Google.Maps
{
/// <summary>
/// Directions may be calculated that adhere to certain restrictions.
/// Restrictions are indicated by use of the avoid parameter, and an
/// argument to that parameter indicating the restriction to avoid.
/// </summary>
[Flags]
public enum Avoid
{
/// <summary>
///
/// </summary>
none = 0,

/// <summary>
///
/// </summary>
highways = 1,

/// <summary>
///
/// </summary>
tolls = 2,

/// <summary>
///
/// </summary>
ferries = 4

}
}
21 changes: 21 additions & 0 deletions src/Google.Maps/AvoidHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Google.Maps
{
internal static class AvoidHelper
{
internal static string MakeAvoidString(Avoid avoid)
{
var sb = new StringBuilder();
foreach (Avoid avoidFlag in Enum.GetValues(typeof (Avoid)))
{
if (avoidFlag != 0 && ((avoid & avoidFlag) == avoidFlag))
sb.Append((sb.Length > 0 ? "|" : "") + avoidFlag.ToString());
}
return sb.ToString();
}
}
}
16 changes: 15 additions & 1 deletion src/Google.Maps/Direction/DirectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public class DirectionRequest
[DefaultValue(TravelMode.driving)]
public TravelMode Mode { get; set; }

/// <summary>
/// (optional) Directions may be calculated that adhere to certain restrictions.
/// </summary>
[DefaultValue(Avoid.none)]
public Avoid Avoid { get; set; }

/// <summary>
/// (optional) If set to true, specifies that the Directions service may provide more than one route alternative in the response.
/// Note that providing route alternatives may increase the response time from the server.
/// </summary>
public bool? Alternatives { get; set; }

/// <summary>The region code, specified as a ccTLD ("top-level domain") two-character value. See also Region biasing.</summary>
/// <see cref="http://code.google.com/apis/maps/documentation/directions/#RequestParameters"/>
/// <seealso cref="https://developers.google.com/maps/documentation/directions/#RegionBiasing"/>
Expand Down Expand Up @@ -105,7 +117,9 @@ internal Uri ToUri()
.Append("waypoints", WaypointsToUri())
.Append("region", Region)
.Append("language", Language)
.Append("sensor", Sensor.Value ? "true" : "false");
.Append("sensor", Sensor.Value ? "true" : "false")
.Append(AvoidHelper.MakeAvoidString(Avoid))
.Append("alternatives", Alternatives.HasValue ? (Alternatives.Value ? "true" : "false") : (string)null);

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

Expand Down
2 changes: 1 addition & 1 deletion src/Google.Maps/Direction/DirectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DirectionService() : this(HttpUri)
}
public DirectionService(Uri baseUri)
{
this.BaseUri = HttpsUri;
this.BaseUri = baseUri;
}
#endregion

Expand Down
3 changes: 3 additions & 0 deletions src/Google.Maps/Direction/DirectionStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class DirectionStep
[JsonProperty("duration")]
public ValueText Duration { get; set; }

[JsonProperty("maneuver")]
public string Maneuver { get; set; }

[JsonProperty("html_instructions")]
public string HtmlInstructions { get; set; }

Expand Down
24 changes: 0 additions & 24 deletions src/Google.Maps/DistanceMatrix/Avoid.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Google.Maps;
using System.Text;

Expand All @@ -35,6 +36,7 @@ public class DistanceMatrixRequest
/// <summary>
/// (optional) Directions may be calculated that adhere to certain restrictions.
/// </summary>
[DefaultValue(Avoid.none)]
public Avoid Avoid { get; set; }

/// <summary>
Expand Down Expand Up @@ -154,7 +156,7 @@ internal Uri ToUri()
.Append("language", Language)
.Append("units", Units.ToString())
.Append("sensor", (Sensor.Value ? "true" : "false"))
.Append("avoid", Avoid.ToString());
.Append("avoid", AvoidHelper.MakeAvoidString(Avoid));

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

Expand Down
3 changes: 2 additions & 1 deletion src/Google.Maps/Google.Maps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="Avoid.cs" />
<Compile Include="AvoidHelper.cs" />
<Compile Include="BaseSigningService.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Direction\DirectionLeg.cs" />
Expand All @@ -84,7 +86,6 @@
<Compile Include="Direction\DirectionService.cs" />
<Compile Include="Direction\DirectionStep.cs" />
<Compile Include="Direction\Polyline.cs" />
<Compile Include="DistanceMatrix\Avoid.cs" />
<Compile Include="DistanceMatrix\DistanceMatrixRequest.cs" />
<Compile Include="DistanceMatrix\DistanceMatrixResponse.cs" />
<Compile Include="DistanceMatrix\DistanceMatrixResponseStatus.cs" />
Expand Down

0 comments on commit 207dccd

Please sign in to comment.