-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22 added geocoding package and factory that is configurable through …
…appsettings.json
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,9 @@ | |
"UserName": "[email protected]", | ||
"Email": "[email protected]", | ||
"Password": "akls;f3W8" | ||
}, | ||
"GeocodingProviders": { | ||
"Provider": "Google", | ||
"ApiKey": "" | ||
} | ||
} |