First, we need to understand that we cannot do the weather forecast function by ourselves. here we only need to call the data returned by the api, the following is an example of how to call the api of www.weather.com.cn. The weather has become an indispensable topic in life... first, we need to understand that we cannot do the weather forecast function by ourselves. here we only need to call the data returned by the api, the following is an example of how to call the api of www.weather.com.cn.
Weather has become an indispensable topic in our life and is closely related to our life. on the right side of my blog, I used php + ajax to create a weather query module.
The ideal status should be that the user automatically obtains local weather information based on different access locations, but the current technology is limited, and only manual query can be completed. This is much simpler, and too many technologies are not used. The main reason is that ajax is used to call an open interface and then process the returned json data.
Interface address: http://www.weather.com.cn/data/cityinfo/101200101.html
Returned value: {"weatherinfo": {"city": "Wuhan", "cityid": "101200101", "temp1": "28 ℃", "temp2 ": "36 ℃", "weather": "Clear to cloudy", "img1": "n0.gif", "img2": "d1.gif", "ptime "}}
The interface address section is "101200101". This ID string is the city id. the ID corresponding to my Baidu to City is encapsulated into an array and can be called directly when used. There are not many core code, mainly because the city -- the ID is relatively large, so I will not post the source code, just package it and share it directly. A friend in need can download it directly!
Some code