PHP queries the weather of a specified city (district/county) through the open API of the meteorological administration

Source: Internet
Author: User
The specific application cannot be said. writing this function is purely for fun. it may be useful in the small pendants of the website, or some living websites are suitable. before entering this topic, you must use PHP to insert the second-level data of provinces, cities, and zones in JSON format into the database before you can perform the following weather query operations. After the provincial and municipal information is imported into the database, let's take a look at the implementation idea: the front-end executes ajax requests through the search box.

The specific application cannot be said. writing this function is purely for fun. it may be useful in the small pendants of the website, or some living websites are suitable. before entering this topic, you must use PHP to insert the second-level data of provinces, cities, and zones in JSON format into the database before you can perform the following weather query operations. After the provincial and municipal information is imported into the database, let's take a look at the implementation idea: the front-end executes ajax requests through the search box, and the backend queries the city code based on the city name, then, the city code is assembled into an API to obtain the city's weather information and return it to the front-end. the code is as follows:

1. foreground code weather. php:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.