Geocod.io API Implementation in C#
Geocod.io is a simple, straightforward and inexpensive geocoding service. I use it at my work to get the positions of job sites needed by some other automated processes. There is a C# client for the API, but when I looked at its usage it seemed more complicated than it should have been. So, just like with Carmine.io, I made my own client. I've made the client available as a NuGet package targeting .NET Standard 1.1. The source code is available on GitHub here.
To use the client, create an instance of GeocodioClient
and pass in an instance of HttpClient
and your API key. For a short example of how it works, take a look at the linked video.
var geocodio = new GeocodioClient(
httpClient,
"{key}"
);
Once you have the client instance you can use the built in helper methods or compose custom requests. For example:
Get Geocode
var geocode = await geocodio.GetGeocodeAsync(
"1600 Pennsylvania Ave NW, Washington, DC 20500"
);
Get Geocode Batch
var geocodeBatch = await geocodio.GetGeocodeBatchAsync(new[] {
"1600 Pennsylvania Ave NW, Washington, DC 20500",
"East Capitol St NE & First St SE, Washington, DC 20004"
});
Get Reverse Geocode
var reverse = await geocodio.GetReverseGeocodeAsync(
"38.897675,-77.036547"
);
Get Reverse Geocode Batch
var reverseBatch = await geocodio.GetReverseGeocodeBatchAsync(new[] {
"38.897675,-77.036547",
"38.898976,-77.038219"
});