ハシウェブ

Web制作、プログラミングに関する情報を発信するブログ

アフィリエイト広告を利用しています

PHPで天気を取得、表示させたい!OpenWeatherMap APIの使い方

この記事は、最初の投稿から3年以上が経過しています。

最終更新から1358日が経過しています。

PHPで天気を取得、表示させたい!OpenWeatherMap APIの使い方

「Webサイトに天気を表示させたい」
「OpenWeatherMapの使い方がわからない」

悩み

こういった悩みにお答えします。

  • PHPで天気を表示させられるようになります。
  • WordPressでも使用できます。
  • 応用次第ではアプリ等にも転用できます。

この記事ではこんなことがわかります。

目次
  1. OpenWeatherMap とは
  2. APIキーを取得する
    1. アカウント登録ページへアクセスする
    2. 必要事項を入力する
    3. 使用目的を入力する
    4. 確認メールが届く
    5. 登録完了
  3. PHPを使ってリクエストする
    1. OpenWeatherMap APIを呼び出す
    2. 天気と温度を取得、表示させる
  4. まとめ

OpenWeatherMap とは

OpenWeatherMapは、現在の天気や天気予報などの無料APIを提供するオンラインサービスです。


Warning: simplexml_import_dom(): Invalid Nodetype to import in /home/hashi84/hsmt-web.com/public_html/wp/wp-content/themes/hsmt-web/functions/custom_ogp.php on line 32

Fatal error: Uncaught Error: Call to a member function xpath() on null in /home/hashi84/hsmt-web.com/public_html/wp/wp-content/themes/hsmt-web/functions/custom_ogp.php:38 Stack trace: #0 /home/hashi84/hsmt-web.com/public_html/wp/wp-content/themes/hsmt-web/blog/openweathermap-api.php(34): get_ogp('https://openwea...') #1 /home/hashi84/hsmt-web.com/public_html/wp/wp-includes/template.php(772): require('/home/hashi84/h...') #2 /home/hashi84/hsmt-web.com/public_html/wp/wp-includes/template.php(716): load_template('/home/hashi84/h...', false, Array) #3 /home/hashi84/hsmt-web.com/public_html/wp/wp-includes/general-template.php(204): locate_template(Array, true, false, Array) #4 /home/hashi84/hsmt-web.com/public_html/wp/wp-content/themes/hsmt-web/single-blog.php(100): get_template_part('blog/openweathe...') #5 /home/hashi84/hsmt-web.com/public_html/wp/wp-includes/template-loader.php(106): include('/home/hashi84/h...') #6 /home/hashi84/hsmt-web.com/public_html/wp/wp-blog-header.php(19): require_once('/home/hashi84/h...') #7 /home in /home/hashi84/hsmt-web.com/public_html/wp/wp-content/themes/hsmt-web/functions/custom_ogp.php on line 38