Esempio n. 1
0
        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
            };
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }