Skip to content

Commit

Permalink
#22 added geocoding package and factory that is configurable through …
Browse files Browse the repository at this point in the history
…appsettings.json
  • Loading branch information
dmnisson committed Nov 9, 2018
1 parent d9b44e5 commit 1b2bbe4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
45 changes: 45 additions & 0 deletions DriverTracker/Domain/GeocoderFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Geocoding;
using Geocoding.Google;
using Geocoding.MapQuest;
using Geocoding.Microsoft;
using Geocoding.Yahoo;

namespace DriverTracker.Domain
{
public static class GeocoderFactory
{

public static bool IsGeocoderEnabled(IConfiguration configuration) {
string[] providerNames = { "Google", "MapQuest", "Microsoft", "Yahoo" };
foreach (string providerName in providerNames) {
if (configuration["GeocodingProviders:Provider"].Equals(providerName))
{
return true;
}
}
return false;
}

public static IGeocoder GetGeocoder(IConfiguration configuration) {
switch (configuration["GeocodingProviders:Provider"])
{
case "Google":
return new GoogleGeocoder() { ApiKey = configuration["GeocodingProviders:ApiKey"] };
case "MapQuest":
return new MapQuestGeocoder(configuration["GeocodingProviders:Key"]) { };
case "Microsoft":
return new BingMapsGeocoder(configuration["GeocodingProviders:BingKey"]) { };
case "Yahoo":
return new YahooGeocoder(
configuration["GeocodingProviders:ConsumerKey"],
configuration["GeocodingProviders:ConsumerSecret"])
{ };
default:
return null;
}
}
}
}
6 changes: 6 additions & 0 deletions DriverTracker/DriverTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="Geocoding.Core" Version="4.0.1" />
<PackageReference Include="Geocoding.Google" Version="4.0.1" />
<PackageReference Include="Geocoding.MapQuest" Version="4.0.1" />
<PackageReference Include="Geocoding.Microsoft" Version="4.0.1" />
<PackageReference Include="Geocoding.Yahoo" Version="4.0.1" />
<PackageReference Include="Accord.Statistics" Version="3.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions DriverTracker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"UserName": "[email protected]",
"Email": "[email protected]",
"Password": "akls;f3W8"
},
"GeocodingProviders": {
"Provider": "Google",
"ApiKey": ""
}
}

0 comments on commit 1b2bbe4

Please sign in to comment.