Weather Service
The WeatherService class provides methods for retrieving current, hourly, and daily weather forecasts.
Get Current Weather Forecast
Use the getCurrent method to retrieve the current weather forecast. Provide coordinates for the desired location, and the forecast will be populated by the time notifyComplete is received.
auto locationCoordinates = Coordinates(48.864716, 2.349014);
weather::LocationForecastList locationForecastList;
WeatherService().getCurrent(
{ locationCoordinates },
locationForecastList,
yourProgressListenerImpl
);
// Wait for the operation to complete (replace with your own synchronization mechanism).
WAIT_UNTIL( std::bind( &YourProgressListenerImpl::IsFinished, yourProgressListenerImpl ), 15000 );
// Process the locationForecastList as needed
GEM_INFO_LOG("Forecast lenght list: %d", locationForecastList.size());
Verify that LocationForecast contains Conditions and each Condition includes a Parameter. If data is unavailable for the specified location and time, the API may return empty lists.
The result contains as many LocationForecast objects as coordinates provided to the coords parameter.
Get Hourly Weather Forecast
Use the getHourlyForecast method to retrieve hourly weather forecasts. Specify the number of hours and coordinates for the desired location.
auto locationCoordinates = Coordinates(48.864716, 2.349014);
weather::LocationForecastList locationForecastList;
WeatherService().getHourlyForecast(
24,
{ locationCoordinates },
locationForecastList,
yourProgressListenerImpl
);
// Wait for the operation to complete (replace with your own synchronization mechanism).
WAIT_UNTIL( std::bind( &YourProgressListenerImpl::IsFinished, yourProgressListenerImpl ), 15000 );
// Process the locationForecastList as needed
GEM_INFO_LOG("Forecast lenght list: %d", locationForecastList.size());
if(!locationForecastList.empty())
GEM_INFO_LOG( "Number of forecasts for the location: %d", locationForecastList.front().forecast.size() );
The number of requested hours must not exceed 240. Exceeding this limit results in an empty response and a error::KOutOfRange error.
Get Daily Weather Forecast
Use the getDailyForecast method to retrieve daily weather forecasts. Specify the number of days and coordinates for the desired location.
auto locationCoordinates = Coordinates(48.864716, 2.349014);
weather::LocationForecastList locationForecastList;
WeatherService().getDailyForecast(
10,
{ locationCoordinates },
locationForecastList,
yourProgressListenerImpl
);
// Wait for the operation to complete (replace with your own synchronization mechanism).
WAIT_UNTIL( std::bind( &YourProgressListenerImpl::IsFinished, yourProgressListenerImpl ), 15000 );
// Process the locationForecastList as needed
GEM_INFO_LOG("Forecast lenght list: %d", locationForecastList.size());
if(!locationForecastList.empty())
GEM_INFO_LOG( "Number of forecasts for the location: %d", locationForecastList.front().forecast.size() );
The number of requested days must not exceed 10. Exceeding this limit results in an empty response and a error::KOutOfRange error.
Get Weather Forecast at certain times in the future
Use the getForecast method to retrieve weather forecasts for specific future times at coordinates. Provide a list of TimeDistanceCoordinate, and getForecast populates as many LocationForecast objects as items in the list.
TimeDistanceCoordinate timeDistanceCoordinate;
timeDistanceCoordinate.coords = Coordinates( 48.864716, 2.349014 );
timeDistanceCoordinate.timespan = 48 * 3600; // 2 days from now
weather::LocationForecastList locationForecastList;
WeatherService().getForecast(
{ timeDistanceCoordinate },
locationForecastList,
yourProgressListenerImpl
);
// Wait for the operation to complete (replace with your own synchronization mechanism).
WAIT_UNTIL( std::bind( &YourProgressListenerImpl::IsFinished, yourProgressListenerImpl ), 15000 );
// Process the locationForecastList as needed
GEM_INFO_LOG("Forecast lenght list: %d", locationForecastList.size());
if(!locationForecastList.empty())
GEM_INFO_LOG( "Number of forecasts for the location: %d", locationForecastList.front().forecast.size() );
The timespan parameter in TimeDistanceCoordinate specifies the time offset into the future for the forecast (e.g 2 days from now).