Esempio n. 1
0
        public static List <WindForecastInstance> GetWindForecastInstances5Days3HourInterval(double latitude, double longitude)
        {
            StringBuilder urlRequest = new StringBuilder();

            urlRequest.Append("http://api.openweathermap.org/data/2.5/forecast?");
            urlRequest.Append($"lat={latitude}&lon={longitude}");
            urlRequest.Append("&APPID=9fbb2cbde0201181c427ff24405bfdeb&units=metric");

            string   jsonResponse = HttpRequestsUtility.Get(urlRequest.ToString());
            JsonRoot forecast     = JsonConvert.DeserializeObject <JsonRoot>(jsonResponse);

            if (forecast.httpReponseCode != "200")
            {
                return(null);
            }

            List <WindForecastInstance> windForecastInstances = new List <WindForecastInstance>();

            foreach (var forecastInstance in forecast.forecastInstances)
            {
                WindForecastInstance windForecastInstance = new WindForecastInstance();
                windForecastInstance.forecastTime         = DateTimeUtility.UnixTimeStampToDateTime(forecastInstance.forecastTime);
                windForecastInstance.windStrengthMps      = forecastInstance.wind.windStrengthMps;
                windForecastInstance.WindDirectionDegrees = forecastInstance.wind.windDirectionDegrees;

                windForecastInstances.Add(windForecastInstance);
            }

            return(windForecastInstances);
        }
Esempio n. 2
0
        private Leg GetFirstLeg(string origin, string destination)
        {
            StringBuilder urlRequest = new StringBuilder();

            urlRequest.Append("https://maps.googleapis.com/maps/api/directions/json?");
            urlRequest.Append("origin=" + origin.Trim().Replace(" ", "+"));
            urlRequest.Append("&destination=" + destination.Trim().Replace(" ", "+"));
            urlRequest.Append("&mode=bicycling&key=AIzaSyByjhJ5jaYEGtO3SrusXXyIkPk0fnuIyis");

            string       jsonResponse = HttpRequestsUtility.Get(urlRequest.ToString());
            MapsJsonRoot path         = JsonConvert.DeserializeObject <MapsJsonRoot>(jsonResponse);

            if (path.Status != "OK")
            {
                return(null);
            }
            return(path.Routes[0].Legs[0]);
        }