예제 #1
0
        public async Task <ElevationResponse> GetElevationByCoordinates(CoordinateRequest coord)
        {
            try
            {
                var requestUrl = string.Format(_appSettings.ElevationApiUrl, coord.Latitude, coord.Longitude, _appSettings.GoogleMapApiKey);
                var request    = new HttpRequestMessage(HttpMethod.Get, requestUrl);

                var client = _clientFactory.CreateClient();

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var res = await response.Content.ReadAsAsync <ElevationResponse>();

                    return(res);
                }
                return(null);
            }
            catch (Exception ex)
            {
                var logMsg = string.Format("Method: GetElevationByCoordinates, Error: {0}", ex.Message);
                //Todo: add log4net.
                throw ex;
            }
        }
예제 #2
0
        public async Task <IActionResult> GetElevationByCoordinates([FromBody] CoordinateRequest coord)
        {
            try
            {
                var result = await _cityMapManager.GetElevationByCoordinates(coord);

                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                var logMsg = string.Format("Controller: GetElevationByCoordinates, Error: {0}", ex.Message);
                //Todo: add log4net.
                return(NotFound());
            }
        }
예제 #3
0
        public async Task <CityMapResponse> GetCityMapByZipCode(string zipCode)
        {
            try
            {
                var openWeather = await GetOpenWeatherByZipCode(zipCode);

                if (openWeather == null || openWeather.coord == null)
                {
                    return(null);
                }
                CoordinateRequest coord = new CoordinateRequest(openWeather.coord.lat, openWeather.coord.lon);
                var timeZone            = await GetTimeZoneByCoordinates(coord);

                if (timeZone == null)
                {
                    return(null);
                }
                var elevation = await GetElevationByCoordinates(coord);

                if (elevation == null)
                {
                    return(null);
                }
                var result = new CityMapResponse
                {
                    City        = openWeather.name,
                    Temperature = openWeather.main.temp,
                    TimeZone    = timeZone.timeZoneName,
                    Elevation   = elevation.results.FirstOrDefault().elevation,
                    Latitude    = coord.Latitude,
                    Longitude   = coord.Longitude,
                    ZipCode     = zipCode
                };
                return(result);
            }
            catch (Exception ex)
            {
                var logMsg = string.Format("Method: GetCityMapByZipCode, Error: {0}", ex.Message);
                //Todo: add log4net.
                throw ex;
            }
        }