前期规划日志 Previous Development Plan :
10/02/2016 & 27/02/2016
后续开发日志 Development Update:
03/05/2016
>前往中文预报页面< >Go to the English forecast page<
以下为主要开发内容 The following is the main content:
由于公差查询器核心已经比较稳定,剩下的主要工作就是利用零碎时间完成公差数据的输入,所以开始着手完成天文天气预报。在研究清楚晴天钟天气图表API的调用方法后,开始着手研究根据访问者IP获取经纬度信息的办法。与公差查询器一样,由于我建站的空间仅支持php语言,所以天气预报页面也使用php来编写。
The core of the tolerance checker has been stable, the rest work is typing the tolerance data which can be done in spare time. I can turn to develop the astronomical weather forecast now. It’s not time-consuming to understand how to use 7Timer!’s API, then the method of obtaining coordinate by visitors’IP address must be figured out. The same reason as the tolerance checker, I choose PHP to set up the page due to my website server’s PHP environment.
为了降低初期的学习难度和开发难度,当然也考虑到测试网络环境,地理信息(IP-经纬度转换和地图)的API选用了百度而没有选用谷歌。
For decreasing the study and develop difficulties, and considering about testing web environment, Baidu Map was selected as geography API instead of Google.
首先通过
First, by using
[php]
$_SERVER["REMOTE_ADDR"]
[/php]
来获得访问者IP地址(这也造成一个问题,获取的是设备接入网络服务商时的IP,造成移动设备通过蜂窝网络接入或透过VPN访问的用户提供的IP是不准确的,造成定位错误,不能实现“本地”天气预报)
to obtain visitor’s IP (There’s problem here. Wrong IP will be fetched if the visitor is using mobile devices through cellular network or visiting the web through VPN, because the code can read the Internet service providers’ IP only)
接着将IP提交给百度地理API(可免费申请有限次数的应用,调用方法请参照百度地图API的相关手册),获取json格式的地理信息,包括地址、经纬度等。
Then hand up the IP to Baidu Map API for returning geography data including address and coordinate in json format. Baidu Map API application can be applied for free.
解码返回的地理信息并提取经纬度信息,分别提交给晴天钟的API(调用方法参见晴天钟的手册)和百度地图API,获取天气预报图表和访问者位置地图。
Decode the json and pick out the coordinate, exchange the weather chart and map image by 7Timer!’s API and Baidu Map API.
再给页面稍微美化一下,成品如图1。
Beautify the page, it works! (As Fig.1)

图.1(Fig.1)
最后,再次声明利用的资源并鸣谢:
预报图表来源: 晴天钟 – 地理信息引擎: MaxMind GeoIP & 百度地图
Resources used by weather forecast and acknowledgements
– Weather Chart Resource: 7Timer! –
– Geography Resource & API: MaxMind GeoIP & Baidu Map –