Weather API
The Weather API template demonstrates how to use a Remote Service Module to get weather conditions and forecasts for locations around the world using the AccuWeather API. This guide will show you how to use the API to get current weather conditions, as well as hourly and daily forecasts and display them in your lenses. Locations are input to the API as coordinates.
To respect user privacy you cannot currently get access to the users location while using the remote service module. You can read more about these restrictions here.
You can read about all the functionality available in the AccuWeather API here.
Using this Template
The template consists of three examples: A multiple day forecast which shows the forecast for 5 days, a current condition example which shows the current weather condition, and finally a simple example which prints the hourly forecast. The first two examples both use prefabs: WeatherMultiday
and WeatherSingleday
which can be customized with new icons or fonts.
Multiple Day Forecast Example
The multiple day forecast example uses the WeatherMultiday prefab to display 5 days of weather forecast.
The MultipleDayForecastController
script is used to populate each WeatherMultiday
prefab with the corresponding data.
Inputs
- AccuWeather API: The AccuWeatherAPI script to use the API.
- City: The city name to use for the forecast. You can view or add cities by their coordinates in
ExampleCities.js
. - UI Weather Days: The input
UIWeatherDay
for each day of the forecast. EachWeatherMultiday
prefab has aUIWeatherDay
script to display weather information. - Loading Object: An optional object to enable/disable based on whether the API request is loading.
- Loading Time: How long to delay before showing the loading UI.
Current Condition Example
The current condition example uses the WeatherSingleday
prefab to display a single day of weather conditions.
The CurrentConditionController
script is used to populate each WeatherSingleday
prefab with the corresponding data.
Inputs
- AccuWeather API: The AccuWeatherAPI script to use the API.
- City: The city name to use for the forecast. You can view or add cities by their coordinates in
ExampleCities.js
. - UI Weather Day: The input
UIWeatherDay
to use to display the weather. - Loading Object: An optional object to enable/disable based on whether the API request is loading.
- Loading Time: How long to delay before showing the loading UI.
Print Hourly Forecast Example
The print hourly forecast example calls the hourly forecast endpoint of the AccuWeather API and prints the forecasted conditions.
Inputs
- AccuWeather API: The AccuWeatherAPI script to use the API.
- City: The city name to use for the forecast. You can view or add cities by their coordinates in
ExampleCities.js
.
Adding a custom city
In order to add a custom city for use as inputs to the various examples simply add the city name and its coordinates to ExampleCities.js.
Previewing Your Lens
You’re now ready to preview your Lens! To preview your Lens in Snapchat, follow the Pairing to Snapchat guide.
Related Guides
Please refer to the guides below for additional information: