Exemple #1
0
        public Geocode()
        {
            var configuration = new ConfigurationBuilder().AddUserSecrets <Geocode>().Build();
            var key           = configuration["GeocodioKey"];

            _geocodio = new GeocodioClient(new HttpClient(), key, true);
        }
                                      )?> GetPointAsync(
            this IGeocodioClient geocodio,
            string address,
            CancellationToken cancellationToken)
        {
            if (!address.HasValue())
            {
                return(null);
            }

            var response = await geocodio.GeocodeAsync(address, Enumerable.Empty <string>(), cancellationToken).ConfigureAwait(false);

            if (response.ResponseStatus != ResponseStatus.Success)
            {
                return(null);
            }

            var result = response.Results.OrderByDescending(
                _ => _.Accuracy).FirstOrDefault();

            if (result is null)
            {
                return(null);
            }

            return(
                result.Location.Latitude,
                result.Location.Longitude
                );
        }