Пример #1
0
        /// <summary>
        /// Test all the methods of the coder.
        /// </summary>
        /// <returns>Task to await.</returns>
        public static async Task AllAsync()
        {
            string apiKey = string.Empty;

            Geocoder coder = new Geocoder(apiKey);

            string address = "1600 Amphitheatre Parkway";

            Console.WriteLine($"Geocode address:'{address}' with language and region");
            PrintResponse(await coder.GeocodeAsync(address, language: "en", region: "us"));

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Geocode address:'{address}' with bounds filter");

            // Antioquia bounds 5.418365,-77.135572|8.8814071,-73.871107
            Bounds boundFilter = new Bounds()
            {
                Southwest = new Southwest()
                {
                    Lat = 5.418365,
                    Lng = -77.135572
                },
                Northeast = new Northeast()
                {
                    Lat = 8.8814071,
                    Lng = -73.871107
                }
            };

            PrintResponse(await coder.GeocodeAsync(address, language: "en", boundsBias: boundFilter));

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Geocode address:'{address}' with component filter country");
            PrintResponse(await coder.GeocodeAsync(address, component: new ComponentFilter()
            {
                Country = "us"
            }));

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Geocode address:'{address}' with component filter country and administrative area");
            PrintResponse(await coder.GeocodeAsync(address, component: new ComponentFilter()
            {
                Country = "us", AdministravieArea = "California"
            }));

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Geocode address:'{address}' with component filter country and administrative area, language and department bounds.");
            PrintResponse(await coder.GeocodeAsync(address, component: new ComponentFilter()
            {
                Country = "us", AdministravieArea = "California"
            }, language: "en", boundsBias: boundFilter));

            Console.WriteLine(string.Empty);
            float latitude  = 37.4224764f;
            float longitude = -122.0842499f;

            Console.WriteLine($"ReverseGeocode lat:{latitude};long:{longitude}");
            PrintResponse(await coder.ReverseGeocodeAsync(latitude, longitude));
        }
Пример #2
0
        public async Task <RuntimeResult> GetWeatherForLocationAsync([Summary("Location")][Remainder] string location)
        {
            var geocodeResults = await Geocoder.GeocodeAsync(location).ConfigureAwait(false);

            var geocode = geocodeResults.FirstOrDefault();

            if (geocode == null)
            {
                return(CommandRuntimeResult.FromError($"I could not find {location}! Try another location."));
            }
            var forecast = await DarkSkyService.GetForecast(
                geocode.Coordinates.Latitude,
                geocode.Coordinates.Longitude,
                _darkSkyParams).ConfigureAwait(false);

            var embeds = await Weather.GetWeatherEmbedsAsync(forecast, geocode).ConfigureAwait(false);

            await ReplyAsync("", embed : embeds.WeatherResults.FirstOrDefault().Build()).ConfigureAwait(false);

            foreach (var alert in embeds.Alerts)
            {
                await ReplyAsync("", embed : alert.Build()).ConfigureAwait(false);
            }
            return(CommandRuntimeResult.FromSuccess());
        }