A .NET 4.5 library that uses OpenCage Geocoder geocoder.
- .NET 4.5
- ServiceStack ver 3.9.71 (last version of non-commercial library)
Reference the library using Nuget https://www.nuget.org/packages/OpenCageGeocoder/
Create an instance of the geocoder library, passing a valid OpenCage Data Geocoder API key as a parameter to the geocoder library's constructor:
var gc = new Geocoder("YOUR_KEY");
Pass a string containing the query or address to be geocoded to the library's Geocode
method:
var result = gc.Geocode("82 Clerkenwell Road, London");
You will get a strongly typed GeocoderResponse object returned.
There are optional paramaters for language, country, and bounds see http://geocoder.opencagedata.com/api.html for explanations
Putting all of this together as a console app, a complete sample would look like this:
var gc = new Geocoder("YOUR_KEY");
var result = gc.Geocode("82 Clerkenwell Road, London");
result.PrintDump(); // ServiceStack human readable object dump to console
Reverse geocoding is almost identical but you pass in a latitude and longitude pair:
var gc = new Geocoder("YOUR_KEY");
var reserveresult = gc.ReverseGeocode(51.4277844, -0.3336517);
reserveresult.PrintDump(); // ServiceStack human readable object dump to console
There is an optional paramaters for language see http://geocoder.opencagedata.com/api.html for explanations