このページのトップへ
天気予報ウィジェットを作成する

天気予報ウィジェットを作成する

サードパーティのサービスからデータを取得してウィジェットを作成する。

中級.png

上級

6K

出版された:

2020年1月1日

酒を楽しむ少女

によって

アンカー 1
開発者を雇う

説明例

In this example, we fetch data from a third-party weather service to create our own customized weather widget.

コード例

タブ1

.

タブ2

.

タブ3

.

このコードによる解決は複雑になる可能性がある。

どのように構築したか

We used OpenWeatherMap as our third-party service. We registered for an API key on their site, which allows us to use their services.


ページ要素


In our site we added the following page elements:

  • Dropdown list of cities: Site visitors select a city to view current weather data. The dropdown choice “values” are defined as city names listed in the third-party service site. We added an event handler in the dropdown element’s Properties panel that runs when a site visitor selects a city.

  • Background image: This image changes depending on whether it’s sunny or cloudy in the selected city.

  • Two text elements: These display the weather description and temperature in the selected city.


コード


Then we added code to do the following:


Define variables: In the event handler that runs when a new city is selected in the dropdown, we defined variables to store the following:

  • The value of the selected city in the dropdown

  • Sources of the sunny and cloudy images

  • Run the fetch request from a backend function. Note that the backend function uses an App ID secret from the Secrets Manager. You will need to get your own App ID and store it in the Secrets Manager to test the example.


Assign weather data to text elements.


We checked if the description was “clear sky” and the temperature was 10 degrees or higher. If so, we displayed the sunny image. If not, we displayed the default cloudy image.


次のステップ


  1. この例をエディターで開き、テンプレートを操作してください。

  2. サイトを公開する。

  3. どのように Veloでの例題の扱い方.

使用したAPI

コード以外の例。

コード以外の例。

関連記事

記事リンク

開発者を雇う

Veloソリューションは強力なツールですが、自力で構築するのは困難です。経験豊富なVelo開発会社に構築をお任せください。

関連例

これは役に立ったか?

はい

|

いいえ

ご意見ありがとう!

カスタムチャートの作成

カスタムチャートの作成

JavaScriptのポストメッセージを使ってHTMLコンポーネントと通信する。

中級.png

上級

Secrets Manager

Secrets Manager

Store API keys in a secure manner using Secrets Manager.

中級.png

中級

Detect Image Labels

Detect Image Labels

Use Google’s vision NPM module to detect an image’s labels.

中級.png

上級

アンカー2
ページ下