Skip to content

Instantly share code, notes, and snippets.

@btompkins
Created January 30, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btompkins/8722291 to your computer and use it in GitHub Desktop.
Save btompkins/8722291 to your computer and use it in GitHub Desktop.
Geocode using Geocodio in C#
public class Geocodio
{
public string ApiKey { get; set; }
public GeocodioResponse GeoCodeByCityState(string address)
{
var client = new RestClient("http://api.geocod.io/v1/");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest("geocode", Method.GET);
request.AddParameter("q", address); // adds to POST or URL querystring based on Method
request.AddParameter("api_key", ApiKey);
// execute the request
var response = client.Execute<GeocodioResponse>(request);
if (response.ErrorException == null) return response.Data;
const string message = "Error retrieving response. Check inner details for more info.";
var geocodioexception = new ApplicationException(message, response.ErrorException);
throw geocodioexception;
}
}
public class GeocodioResponse
{
public List<GeocoioResults> Results { get; set; }
public class GeocoioResults
{
public string FormattedAddress { get; set; }
public GeocodioLatLng Location { get; set; }
}
public class GeocodioLatLng
{
public double Lat { get; set; }
public double Long { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment