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

Update Geocoding.Here to use "Geocoding and Search API v7". #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Includes a model and interface for communicating with five popular Geocoding pro
* [Bing Maps (aka Virtual Earth)](http://www.microsoft.com/maps/) - [docs](http://msdn.microsoft.com/en-us/library/ff701715.aspx)
* :warning: MapQuest [(Commercial API)](http://www.mapquestapi.com/) - [docs](http://www.mapquestapi.com/geocoding/)
* :warning: MapQuest [(OpenStreetMap)](http://open.mapquestapi.com/) - [docs](http://open.mapquestapi.com/geocoding/)
* [HERE](https://www.here.com/) - [docs](https://developer.here.com/documentation)
* [HERE](https://www.here.com/) - [docs](https://developer.here.com/documentation/geocoding-search-api)

The API returns latitude/longitude coordinates and normalized address information. This can be used to perform address validation, real time mapping of user-entered addresses, distance calculations, and much more.

Expand Down Expand Up @@ -73,7 +73,7 @@ You will need a [consumer secret and consumer key](http://developer.yahoo.com/bo

MapQuest API requires a key. Sign up here: (http://developer.mapquest.com/web/products/open)

HERE requires an [app ID and app Code](https://developer.here.com/?create=Freemium-Basic&keepState=true&step=account)
HERE requires an [API key](https://developer.here.com/?create=Freemium-Basic&keepState=true&step=account).

## How to Build from Source

Expand Down
78 changes: 78 additions & 0 deletions src/Geocoding.Core/QueryBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;

namespace Geocoding
{
/// <summary>
/// Provides a custom constructor for Uri query strings.
/// </summary>
public class QueryBuilder
{
private readonly List<QueryParameter> parameters = new List<QueryParameter>();

/// <summary>
/// Adds the parameter.
/// </summary>
/// <param name="parameter">The parameter to add.</param>
/// <returns>This instance of the Query builder, to allow Fluent calls.</returns>
public QueryBuilder AddParameter(QueryParameter parameter)
{
parameters.Add(parameter);
return this;
}

/// <summary>
/// Adds the parameter.
/// </summary>
/// <param name="name">The name/key of the parameter.</param>
/// <param name="value">The value of parameter.</param>
/// <remarks>Both name and value will be Url Encoded.</remarks>
/// <returns>This instance of the Query builder, to allow Fluent calls.</returns>
public QueryBuilder AddParameter(String name, String value)
{
return AddParameter(new QueryParameter(name, value));
}

/// <summary>
/// Adds the parameter if the value is not null or Empty.
/// </summary>
/// <param name="name">The name/key of the parameter.</param>
/// <param name="value">The value of parameter.</param>
/// <remarks>Both name and value will be Url Encoded.</remarks>
/// <returns>This instance of the Query builder, to allow Fluent calls.</returns>
public QueryBuilder AddNonEmptyParameter(String name, String value)
{
if (!string.IsNullOrEmpty(value))
{
AddParameter(new QueryParameter(name, value));
}
return this;
}

/// <summary>
/// Adds the parameter.
/// </summary>
/// <param name="parameters">The parameter to add.</param>
/// <returns>This instance of the Query builder, to allow Fluent calls.</returns>
public QueryBuilder AddParameters(IEnumerable<QueryParameter> parameters)
{
foreach (QueryParameter parameter in parameters)
{
AddParameter(parameter);
}
return this;
}

/// <summary>
/// Gets the query string.
/// </summary>
public String GetQuery(String separator = "&")
{
return String.Join(separator, parameters.Select(p => p.Query));
}
}
}
29 changes: 29 additions & 0 deletions src/Geocoding.Core/QueryParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.Net;

namespace Geocoding
{
public class QueryParameter
{
public String Name { get; }
public String Value { get; }

public QueryParameter(String name, String value)
{
Name = name;
Value = value;
}

public String Query
{
get
{
return String.Format(CultureInfo.InvariantCulture,
"{0}={1}",
WebUtility.UrlEncode(Name),
WebUtility.UrlEncode(Value));
}
}
}
}
11 changes: 5 additions & 6 deletions src/Geocoding.Here/HereAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace Geocoding.Here
{
public class HereAddress : Address
{
readonly string street, houseNumber, city, state, country, postalCode;
readonly HereLocationType type;
readonly string street, houseNumber, city, state, country, postalCode, resultType;

public string AddressLine
{
Expand Down Expand Up @@ -37,13 +36,13 @@ public string PostalCode
get { return postalCode ?? ""; }
}

public HereLocationType Type
public String ResultType
{
get { return type; }
get { return resultType; }
}

public HereAddress(string formattedAddress, Location coordinates, string street, string houseNumber, string city,
string state, string postalCode, string country, HereLocationType type)
string state, string postalCode, string country, string resultType)
: base(formattedAddress, coordinates, "HERE")
{
this.street = street;
Expand All @@ -52,7 +51,7 @@ public HereAddress(string formattedAddress, Location coordinates, string street,
this.state = state;
this.postalCode = postalCode;
this.country = country;
this.type = type;
this.resultType = resultType;
}
}
}
Loading