OpenWeatherMapのAPIをPHPから呼び出して天気予報を表示する方法について

f:id:moshimore:20180529181625j:plain
天気予報APIは各種サイトで展開されていますが、今回はOpenWeatherMapのAPIを使ってみたいと思います。

プラン比較

OpenWeatherMapのAPIは無料プランと有料プランがあり、違いは以下の通りです。

ユーザー登録

OpenWeatherMapサイトの上にあるSign Upからユーザー登録します。今現在(2018/5/29)では以下のようなことが書かれていますが、そのままGoogle翻訳すると次の通りです。

原文

We will use information you provided for management and administration purposes and for keeping you informed by mail, telephone, email and SMS of other products and services from us and our partners. You can proactively manage your preferences or opt-out of communications with us at any time using Privacy Centre. You have the right to access your data held by us or to request your data to be deleted. For full details please see the OpenWeather Privacy Policy.

I am 16 years old or over
I consent to storage and processing of my data by OpenWeather accordingly with Privacy Policy
I consent to receive communications from OpenWeather Group of Companies and their partners:

System news (API usage alert, system update, temporary system shutdown, etc)
Product news (change of price, new product features, etc)
Corporate news (our life, launch of new services, etc)

翻訳

当社は、管理および管理の目的で提供した情報を使用し、当社およびパートナーからの他の製品およびサービスの郵送、電話、電子メールおよびSMSによる通知をお客様に提供します。プライバシー・センターを使用して、いつでも事前にプリファレンスを管理したり、当社との通信をオプトアウトすることができます。お客様は、当社が保有するお客様のデータにアクセスする権利、またはお客様のデータを削除するよう要求する権利を有します。詳細については、OpenWeatherのプライバシーポリシーをご覧ください。

私は16歳以上です
OpenWeatherによるデータの保存と処理に私は同意します。プライバシーポリシー
私は、OpenWeatherグループ企業およびそのパートナーからの連絡を受けることに同意します。

システムニュース(API使用警告、システムアップデート、一時的なシステムシャットダウンなど)
製品ニュース(価格の変更、新製品の機能など)
企業ニュース(私たちの人生、新しいサービスの立ち上げなど)

今回は、上から3つにチェックを入れておきました。
登録した後には次のアンケートが表示されました。

原文

How and where will you use our API?
Hi! We are doing some housekeeping around thousands of our customers. Your impact will be much appreciated. All you need to do is to choose in which exact area you use our services.

翻訳

どのようにAPIを使用しますか?
こんにちは!私たちは何千人ものお客様の家事を管理しています。あなたのインパクトは非常に高く評価されます。あなたがする必要があるのは、あなたが私たちのサービスを使用する正確なエリアを選択することだけです。

以上、OpenWeatherMapのAPIをPHPから呼び出して天気予報を表示する方法についてでした。