Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            // Create an instance of the Google Geocodes API: contacts google, retrieves JSON file, and parses lat and long.
            GoogleGeocodingAPI geocodeAPI = new GoogleGeocodingAPI();

            // Create DarkSky data model which contains all weather info for the submitted geolocation.
            DarkSkyAPIModel weatherForecast = new DarkSkyAPIModel(geocodeAPI.geoLatitude, geocodeAPI.geoLongtitude);

            Console.ReadLine();
        }
        public float getCurrentWeather(string cityName)
        {
            float temperature = 0f;

            float locationLongitude = getLocationLongitude(cityName);
            float locationLatitude  = getLocationLatitude(cityName);

            string response = getResponse(darkSkyAPIEndpoint.getWeatherEndpoint(locationLatitude, locationLongitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <DarkSkyAPIModel> jsonParser = new JsonParser <DarkSkyAPIModel>())
            {
                DarkSkyAPIModel darkSkyAPIModel = new DarkSkyAPIModel();
                darkSkyAPIModel = jsonParser.parse(response);

                temperature = darkSkyAPIModel.currently.temperature;
            }

            return(temperature);
        }
        public List <DarkSkyForecast> getForecast(string cityName)
        {
            List <DarkSkyForecast> forecastList = new List <DarkSkyForecast>();

            float locationLongitude = getLocationLongitude(cityName);
            float locationLatitude  = getLocationLatitude(cityName);

            string response = getResponse(darkSkyAPIEndpoint.getWeatherEndpoint(locationLatitude, locationLongitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <DarkSkyAPIModel> jsonParser = new JsonParser <DarkSkyAPIModel>())
            {
                DarkSkyAPIModel darkSkyAPIModel = new DarkSkyAPIModel();
                darkSkyAPIModel = jsonParser.parse(response);

                foreach (Daily dailyForecast in darkSkyAPIModel.daily)
                {
                    forecastList.Add(new DarkSkyForecast(dailyForecast.data.time, dailyForecast.data.temperatureMax, dailyForecast.data.temperatureMin));
                }
            }

            return(forecastList);
        }