Ejemplo n.º 1
0
        public IActionResult Index(double longitude, double latitude, string rawAddress = "")
        {
            ViewData["weatherData"] = new WeatherData();
            ViewData["location"]    = new LocationData();

            if (rawAddress.Length == 0)
            {
                WeatherData weather = _weatherService.CallDarkSky(longitude, latitude).Result;
                ViewData["weatherData"] = weather;
                return(View());
            }
            else
            {
                // use LocationService to get location data and save the location object:
                LocationData geocode = _location.LocationSearch(rawAddress).Result;

                ViewData["location"] = geocode;

                if (geocode is null)
                {
                    return(View("error"));
                }
                else
                {
                    double result_lat = geocode.results[0].geometry.location.lat;
                    double result_lng = geocode.results[0].geometry.location.lng;

                    WeatherData weather = _weatherService.CallDarkSky(result_lng, result_lat).Result;

                    ViewData["weatherData"] = weather;

                    return(View());
                }
            }
        }