Skip to content

Commit

Permalink
Merge branch 'master' into netcore
Browse files Browse the repository at this point in the history
* master:
  Don't include test project in ilmerged output
  Register google as default geocoder for example app
  Update .gitignore for VS 2015
  Updating readme mapquest issues
  Upgrade Geocoding.Net in Example.sln. Can't reproduce chadly#45 and chadly#48. They are already fixed by commit ecc8cf6
  Split tests for special characters and Street intersections (by ampersand)
  Test MapQuest Commercial API
  Implemented Google Geocoding channel feature (chadly#63)
  Bump version
  Add Google component filters for administrative areas, postal codes and countries (chadly#60)
  Adding Mixed SideOfStreet to MapQuest
  Bump minor version ahead of release
  Fixing space formatting
  Minor change
  Added place_id to GoogleAddress (chadly#52)
  update example output to match current return (chadly#54)

# Conflicts:
#	Google/Google.csproj
#	Tests/MapQuestBatchGeocoderTest.cs
#	geocoding.nuspec
#	src/Geocoding.Google/GoogleGeocoder.cs
#	teamcity.targets
#	test/Geocoding.Tests/GoogleGeocoderTest.cs
#	test/Geocoding.Tests/MapQuestGeocoderTest.cs
  • Loading branch information
adamhathcock committed Dec 13, 2016
2 parents 36b598d + 716941b commit e3e44e1
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 111 deletions.
75 changes: 2 additions & 73 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,20 @@ project.lock.json
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
.vs
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
_ReSharper*

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML



############
## Windows
############
Expand All @@ -106,5 +37,3 @@ Thumbs.db

# Folder config file
Desktop.ini
.directory
*.userprefs
12 changes: 12 additions & 0 deletions Google/GoogleComponentFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Geocoding.Google
{
public class GoogleComponentFilter
{
public string ComponentFilter { get; set; }

public GoogleComponentFilter(string component, string value)
{
ComponentFilter = string.Format("{0}:{1}", component, value);
}
}
}
9 changes: 9 additions & 0 deletions Google/GoogleComponentFilterType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Geocoding.Google
{
public struct GoogleComponentFilterType
{
public const string AdministrativeArea = "administrative_area";
public const string PostalCode = "postal_code";
public const string Country = "country";
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Includes a model and interface for communicating with five popular Geocoding pro
* [Google Maps](https://developers.google.com/maps/) - [docs](https://developers.google.com/maps/documentation/geocoding/)
* [Yahoo! BOSS Geo Services](http://developer.yahoo.com/boss/geo/) - [docs](http://developer.yahoo.com/geo/placefinder/guide/index.html)
* [Bing Maps (aka Virtual Earth)](http://www.microsoft.com/maps/) - [docs](http://msdn.microsoft.com/en-us/library/ff701715.aspx)
* :warning: MapQuest [(Comercial API)](http://www.mapquestapi.com/) - [docs](http://www.mapquestapi.com/geocoding/)
* :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/)

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.

See latest [release notes](https://github.com/chadly/Geocoding.net/releases/latest).

:warning: There are some open issues ([#29](https://github.com/chadly/Geocoding.net/issues/29), [#45](https://github.com/chadly/Geocoding.net/issues/45), [#48](https://github.com/chadly/Geocoding.net/issues/48)) regarding MapQuest which have some workarounds. If you would like to help fix the issues, PRs are welcome.
:warning: There is a potential issue ([#29](https://github.com/chadly/Geocoding.net/issues/29)) regarding MapQuest that has a workaround. If you would like to help fix the issue, PRs are welcome.

##Installation

Expand All @@ -31,8 +31,8 @@ Or download the [latest release](https://github.com/chadly/Geocoding.net/release
```csharp
IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "this-is-my-optional-google-api-key" };
IEnumerable<Address> addresses = geocoder.Geocode("1600 pennsylvania ave washington dc");
Console.WriteLine("Formatted: " + addresses.First().FormattedAddress); //Formatted: 1600 Pennslyvania Avenue Northwest, Presiden'ts Park, Washington, DC 20500, USA
Console.WriteLine("Coordinates: " + addresses.First().Coordinates.Latitude + ", " + addresses.First().Coordinates.Longitude); //Coordinates: 38.8978378, -77.0365123
Console.WriteLine("Formatted: " + addresses.First().FormattedAddress); //Formatted: 1600 Pennsylvania Ave SE, Washington, DC 20003, USA
Console.WriteLine("Coordinates: " + addresses.First().Coordinates.Latitude + ", " + addresses.First().Coordinates.Longitude); //Coordinates: 38.8791981, -76.9818437
```

It can also be used to return address information from latitude/longitude coordinates (aka reverse geocoding):
Expand Down
5 changes: 3 additions & 2 deletions examples/Example.Web/Example.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
<Reference Include="Autofac.Integration.Mvc">
<HintPath>..\packages\Autofac.Mvc4.3.1.0\lib\net40\Autofac.Integration.Mvc.dll</HintPath>
</Reference>
<Reference Include="Geocoding">
<HintPath>..\packages\Geocoding.net.3.3.0\lib\net40\Geocoding.dll</HintPath>
<Reference Include="Geocoding, Version=3.5.0.0, Culture=neutral, PublicKeyToken=7c714700b88674c7, processorArchitecture=MSIL">
<HintPath>..\packages\Geocoding.net.3.5.0\lib\net40\Geocoding.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down
3 changes: 3 additions & 0 deletions examples/Example.Web/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Geocoding.Google;
using Geocoding.Microsoft;
using Geocoding.Yahoo;
using Geocoding.MapQuest;

namespace Example.Web
{
Expand Down Expand Up @@ -36,6 +37,8 @@ IContainer InitializeContainer()
//http://developer.yahoo.com/boss/geo/BOSS_Signup.pdf
builder.Register(c => new YahooGeocoder("my-yahoo-consumer-key", "my-yahoo-consumer-secret")).As<IGeocoder>();

builder.Register(c => new MapQuestGeocoder("mapquest-key") { UseOSM = true }).As<IGeocoder>();

//https://developers.google.com/maps/documentation/javascript/tutorial#api_key
//a server key is optional with Google
builder.Register(c => new GoogleGeocoder
Expand Down
2 changes: 1 addition & 1 deletion examples/Example.Web/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
2 changes: 1 addition & 1 deletion examples/Example.Web/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="Autofac" version="3.1.5" targetFramework="net45" />
<package id="Autofac.Mvc4" version="3.1.0" targetFramework="net45" />
<package id="Geocoding.net" version="3.3.0" targetFramework="net45" />
<package id="Geocoding.net" version="3.5.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
Expand Down
41 changes: 40 additions & 1 deletion src/Geocoding.Google/BusinessKey.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace Geocoding.Google
{
Expand All @@ -12,10 +13,48 @@ public class BusinessKey
public string ClientId { get; set; }
public string SigningKey { get; set; }

public BusinessKey(string clientId, string signingKey)
/// <summary>
/// More details about channel
/// https://developers.google.com/maps/documentation/directions/get-api-key
/// https://developers.google.com/maps/premium/reports/usage-reports#channels
/// </summary>
private string channel;
public string Channel
{
get
{
return channel;
}
set
{
if (string.IsNullOrWhiteSpace(value))
{
return;
}
string formattedChannel = value.Trim().ToLower();
if (Regex.IsMatch(formattedChannel, @"^[a-z_0-9.-]+$"))
{
channel = formattedChannel;
}
else
{
throw new ArgumentException("Must be an ASCII alphanumeric string; can include a period (.), underscore (_) and hyphen (-) character", "channel");
}
}
}
public bool HasChannel
{
get
{
return !string.IsNullOrEmpty(Channel);
}
}

public BusinessKey(string clientId, string signingKey, string channel = null)
{
this.ClientId = CheckParam(clientId, "clientId");
this.SigningKey = CheckParam(signingKey, "signingKey");
this.Channel = channel;
}

string CheckParam(string value, string name)
Expand Down
13 changes: 10 additions & 3 deletions src/Geocoding.Google/GoogleAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class GoogleAddress : Address
readonly GoogleAddressComponent[] components;
readonly bool isPartialMatch;
readonly GoogleViewport viewport;
readonly string placeId;

public GoogleAddressType Type
public GoogleAddressType Type
{
get { return type; }
}
Expand All @@ -36,13 +37,18 @@ public GoogleViewport Viewport
get { return viewport; }
}

public string PlaceId
{
get { return placeId; }
}

public GoogleAddressComponent this[GoogleAddressType type]
{
get { return Components.FirstOrDefault(c => c.Types.Contains(type)); }
}

public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components,
Location coordinates, GoogleViewport viewport, bool isPartialMatch, GoogleLocationType locationType)
Location coordinates, GoogleViewport viewport, bool isPartialMatch, GoogleLocationType locationType, string placeId)
: base(formattedAddress, coordinates, "Google")
{
if (components == null)
Expand All @@ -53,6 +59,7 @@ public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddr
this.isPartialMatch = isPartialMatch;
this.viewport = viewport;
this.locationType = locationType;
}
this.placeId = placeId;
}
}
}
12 changes: 12 additions & 0 deletions src/Geocoding.Google/GoogleComponentFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Geocoding.Google
{
public class GoogleComponentFilter
{
public string ComponentFilter { get; set; }

public GoogleComponentFilter(string component, string value)
{
ComponentFilter = string.Format("{0}:{1}", component, value);
}
}
}
9 changes: 9 additions & 0 deletions src/Geocoding.Google/GoogleComponentFilterType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Geocoding.Google
{
public struct GoogleComponentFilterType
{
public const string AdministrativeArea = "administrative_area";
public const string PostalCode = "postal_code";
public const string Country = "country";
}
}
17 changes: 15 additions & 2 deletions src/Geocoding.Google/GoogleGeocoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public BusinessKey BusinessKey
public string Language { get; set; }
public string RegionBias { get; set; }
public Bounds BoundsBias { get; set; }
public IList<GoogleComponentFilter> ComponentFilters { get; set; }

public string ServiceUrl
{
Expand Down Expand Up @@ -94,6 +95,11 @@ public string ServiceUrl
{
builder.Append("&client=");
builder.Append(WebUtility.UrlEncode(BusinessKey.ClientId));
if (BusinessKey.HasChannel)
{
builder.Append("&channel=");
builder.Append(HttpUtility.UrlEncode(BusinessKey.Channel));
}
}

if (BoundsBias != null)
Expand All @@ -108,6 +114,12 @@ public string ServiceUrl
builder.Append(BoundsBias.NorthEast.Longitude.ToString(CultureInfo.InvariantCulture));
}

if (ComponentFilters != null)
{
builder.Append("&components=");
builder.Append(string.Join("|", ComponentFilters.Select(x => x.ComponentFilter)));
}

return builder.ToString();
}
}
Expand Down Expand Up @@ -238,6 +250,7 @@ private IEnumerable<GoogleAddress> ParseAddresses(XPathNodeIterator nodes)
XPathNavigator nav = nodes.Current;

GoogleAddressType type = EvaluateType((string)nav.Evaluate("string(type)"));
string placeId = (string)nav.Evaluate("string(place_id)");
string formattedAddress = (string)nav.Evaluate("string(formatted_address)");

var components = ParseComponents(nav.Select("address_component")).ToArray();
Expand All @@ -261,7 +274,7 @@ private IEnumerable<GoogleAddress> ParseAddresses(XPathNodeIterator nodes)
bool isPartialMatch;
bool.TryParse((string)nav.Evaluate("string(partial_match)"), out isPartialMatch);

yield return new GoogleAddress(type, formattedAddress, components, coordinates, viewport, isPartialMatch, locationType);
yield return new GoogleAddress(type, formattedAddress, components, coordinates, viewport, isPartialMatch, locationType, placeId);
}
}

Expand Down Expand Up @@ -361,4 +374,4 @@ private GoogleLocationType EvaluateLocationType(string type)
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/Geocoding.MapQuest/SideOfStreet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ public enum SideOfStreet
/// Right
/// </summary>
R,
/// <summary>
/// Mixed
/// </summary>
M,
}
}
Loading

0 comments on commit e3e44e1

Please sign in to comment.