public GoogleGeocodingApiTest() { IConfiguration config = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory())) .AddJsonFile("appsettings.json", true, true) .Build(); _googleGeocodingApi = new GoogleGeocodingApi(config["GoogleApiKey"]); _client = new HttpClient { MaxResponseContentBufferSize = MaxResponseContentBufferSize }; }
public async Task <GeocodedAddress> GeocodeAddress(string address) { var httpClient = new HttpClient(); var googleGeocodingApi = new GoogleGeocodingApi(Configuration["GoogleApiKey"]); var loc = await googleGeocodingApi.SearchAddress(httpClient, address); var result = new GeocodedAddress { County = loc.Results.FirstOrDefault()?.CityShortName?.Replace("County", ""), State = loc.Results.FirstOrDefault()?.StateLongName }; return(result); }
public async Task <Location> LocationFromAddress(string address, double?approximateLat = null, double?approximateLon = null) { Location approximateLocation = null; if (approximateLat != null && approximateLon != null) { approximateLocation = new Location(approximateLat.Value, approximateLon.Value); } GoogleGeocodingApi api = new GoogleGeocodingApi(); var location = await api.LocationFromAddress(address, approximateLocation); return(location); }