Blog

Get the weather forecast in your webapp with this web component, paper-weather

By  
Binh Bui
Binh Bui
·
On Nov 21, 2018 2:26:00 PM
·
Web Components Wednesday (WCW) blog series is created for two purposes: introducing easy-to-use components and educating people on the concept of Web Components. All the WCW blogs can be found here.

[Blog] paper-weather-thumbnailWhen satellites came in action, they helped human in many modern technologies, such as broadcasting channels, making a call and paying with credit cards in remote areas, tracking flights, and even assisting farmers to get the best time for irrigating their fields. Along with those, we also achieved the so-called weather prediction.

With that technology, there comes a plenty of online services for fetching the data, and getting the information can be as simple as opening an app. Today, we are going to take a look at one Material Design component, namely paper-weather, which is a highly convenient and functional weather element.

Get Your Weather Prediction Anytime, Anywhere

If you are planning to go to a park or do some camping, you might want to pick a sunny day. That’s why paper-weather can give you the forecast for 7 days. All you need to do is to set the location to your desired city, or its zip code, and voila!

[Blog] paper-weather-full-F

From there, you can see the current weather condition (cloudy, sunny, rainstorm), and also the high/low and condition forecast for the upcoming days. There are around 20 weather conditions in total, and each of them has its own elegant design.

[Blog] paper-weather-all-conditions

Imperial Unit and Metric Unit

By default, the component uses the Imperial unit. However, you can quickly change this by setting unit to “c,” which stands for Celsius.

[Blog] paper-weather-full-extra-data

As you can see, we can also display extra data, like the sunrise time or wind speed. This can be enabled by applying the attribute show-extra-data. What more? For mobile users, a more compact view can be taken into use with the attribute list. The component makes sure that data is still appropriately displayed using minimal space while being fully responsive.

[Blog] paper-weather-full-extra-data

...

...

Ideas for Localization

[Blog] paper-weather-localziation

While using this component inside an app, you certainly want a good localization system so that it can automatically detect your user's location and measurement system.

For the location, you can adopt some reverse geocoding services or even a web component, like the one we introduced in this previous blog post, geo-codec.

For the unit, only three countries are using the Imperial system, which are Liberia, Myanmar, and the USA. Paper-weather provides a property called lastResponse, which you can use to get the latest response in JSON. From there, you can quickly grab the country from the key location and then detect, if it’s one of those three countries. If the condition passes, it changes to use the default system, otherwise, we use metric units.

Compatibility

The table below will shortly summarize the component info and compatibility on multiple platforms:

Component

Library

Mobile

Browsers

paper-weather

Polymer#1.9 - 2

paper-weather web components browsers compatibility

Final Words

Weather plays a vital role in our everyday life. With this component, you might make it one step easier for users to make better decisions for their plans. Moreover, it’s simple to use: just import and add a pair of HTML tags. Christmas is coming so make sure to use this for snow prediction.

Click here for more awesome web components

Relevant articles:

Binh Bui
Binh Bui
Binh is a Growth Marketer involved with multiple domains ranging from running experiments, campaigns to doing product-led growth stuff. He likes using his brain and he likes random discussions. Out of work, you can see Binh in the Schrodinger gym. Follow Binh on Twitter @buibaobin
Other posts by Binh Bui