Creating a weather app using PowerApps
One of the great things about PowerApps is that every month it gets better and better with more capabilities in the platform as well as new connectors that provide more flexibility connecting to SaaS services. Last month one of such connectors was the MSN Weather that gives you the ability to read the current weather on a specific location, or even the forecast for tomorrow and others.
MSN Weather API
While I don’t think you want to build the next Weather App (there are plenty out there), having the capability of incorporating weather information to your application and correlate to any other data on it is very powerful, whether for planning purposes, delivery, travel plans, or scheduling, or others it can save your users from having to go to multiple places. In addition, with Microsoft Flow you could setup some automated tasks that trigger when the weather changes, and such.
What we will be building
For this quick sample we will be creating the following application using PowerApps that allow you to enter a location in the Input box and will provide you the weather, conditions, pressure, and other information. It also allows you to use the current location to get the weather for it. We currently do not have a reverse geocoding API but the MSN Weather API allows you to provide the Location in coordinates. Of course like all other PowerApps, this application will run in iOS (iPhone, iPad), Android, Windows Phone, Web, and Windows Desktop which makes it extremely powerful and all of this in less than five minutes.
Building the Weather App
At a high level the strategy we will use since we want to have the user click the “Search button” as an explicit action, we’ll store the result of calling MSNWeather.CurrentWeather in the OnSelect of the Search button into a context variable that then we’ll use to display in all the other controls. We’ll add another icon to set the current location coordinates. That’s it… nothing else needed.
- In Windows, launch PowerApps
- We’ll initialize the default location when first launching the app, for that: on the Screen set the following properties:
- OnVisible = UpdateContext({LastLocation: "Redmond, WA"})
- We’ll add the “set the current location” button, for that: Add an Icon (I used the “Map”) icon for simplicity and set the following properties:
- OnSelect = UpdateContext({LastLocation: Location.Latitude & ", " & Location.Longitude})
- We’ll load the last location as a default for the textbox: Add a new Text Input control and set the following properties
- Default = LastLocation
- HintText = "Enter location"
- Add the “Units” radio group, for that add a Radio control with the following properties:
- Items = ["Imperial", "Metric"]
- Default = "Imperial"
- We’ll add the Search button, for that:
- OnSelect = UpdateContext({Weather: MSNWeather.CurrentWeather(TextInput1.Text, Radio1.Selected.Value)})
- Finally add all the controls to visualize the data, I used the following:
- Temperature: Weather.responses.weather.current.temp & " " & Weather.units.temperature
- Conditions: Weather.responses.weather.current.cap
- Pressure: Weather.responses.weather.current.baro & " " & Weather.units.pressure
- UV Index: Weather.responses.weather.current.uv & " " & Weather.responses.weather.current.uvDesc
- Dew Point: Weather.responses.weather.current.dewPt & " o"
- Humidity: Weather.responses.weather.current.rh & " %"
- Sky: Weather.responses.weather.current.sky
- Wind: Weather.responses.weather.current.windSpd & " " & Weather.units.speed
- Visibility: Weather.responses.weather.current.vis
- Last Updated: Text(DateTimeValue(Weather.responses.weather.current.created), DateTimeFormat.ShortDateTime)
- Coordinates: Weather.responses.source.coordinates.lat & ", " & Weather.responses.source.coordinates.lon
- Open in Browser: Launch(Launch(Weather.responses.source.clickThrough))
Anyway, hopefully this shows how easy it is to add a data source to PowerApps. If you need to learn more about which APIs are available and the properties on each you can go to: https://blogs.msdn.microsoft.com/carlosag/2016/11/22/the-unofficial-powerapps-connectors-reference-draft/
Download a copy of the app here
Comments
- Anonymous
April 15, 2017
Hi Carlos, Thanks for the example but I get an error unauthorized -- the request URL does not match any API runtime URL - Anonymous
May 01, 2017
All is Good but in my view, But one thing that every Weather app lacking: either Weather apps display a lot of unrequited alerts for weather changes (talking about google app) but i never seen even a single alert when it should be. So, i have faith in MS and i think this app will gonna overcome this issue. Now, i am upto using this app.