#Generic C# Geocoding API
Includes a model and interface for communicating with three popular Geocoding providers. Current implementations include:
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.
##Installation
Install via nuget:
Install-Package Geocoding.net
Or download the latest release and add a reference to Geocoding.dll
in your project.
##Example Usage
###Simple Example
IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "this-is-my-optional-google-api-key" };
Address[] addresses = geocoder.Geocode("1600 pennsylvania ave washington dc");
It can also be used to return address information from latitude/longitude coordinates (aka reverse geocoding):
IGeocoder geocoder = new YahooGeocoder("consumer-key", "consumer-secret");
Address[] addresses = geocoder.ReverseGeocode(38.8976777, -77.036517);
###Using Provider-Specific Data
GoogleGeocoder geocoder = new GoogleGeocoder();
GoogleAddress[] addresses = geocoder.Geocode("1600 pennsylvania ave washington dc");
var country = addresses.Where(a => !a.IsPartialMatch).Select(a => a[GoogleAddressType.Country]).First();
Console.WriteLine("Country: " + country.LongName + ", " + country.ShortName); //Country: United States, US
The Microsoft and Yahoo implementations each provide their own address class as well, BingAddress
and YahooAddress
.
###More Examples
A more in-depth runnable example of how this library can be integrated into an MVC4 application can be found in the latest release package. Download it and run locally.
##API Keys
Google allows anonymous access to it's API, but if you start hitting rate limits, you must sign up for a new Server API Key.
Bing requires an API key to access its service.
You will need a consumer secret and consumer key (PDF) for Yahoo.
##How to Build from Source
In order to compile the solution in Visual Studio, you must first run build.bat. This will run a basic Debug build without running any tests. The build process generates some files that are needed to compile in Visual Studio.
You will need to generate API keys for each respective service to run the service tests. Edit App.config in the Tests project and put in your API keys.
Help support development: 1K33yhGwx3zLopyJuAHWDn8XrMjM6Twwr8