>Astronomical Weather Forecast Dev Log – 天文天气预报开发日志<
1.0版本由IP获取经纬度没多大问题,但是百度地图API只能提供东亚地区城市的经纬度信息,然而晴天钟可以提供全球绝大部分地区的预报信息,所以不太匹配。按照晴天钟介绍中,其本身所使用的经纬度信息主要取自谷歌和GeoIP。我决定将经纬度信息引擎换成GeoIP。
Version 1.0 worked well, but it can provide forecast of East Asian cities due to the Baidu Map API area limit. It was a little wasteful for 7Timer!’s global forecast. Reading from 7Timer!’s introduction, coordinate resources what it is using are Google and GeoIP. I decided to changed into GeoIP as well.
调用方法也不复杂,就是需要前往MaxMind下载开源的全球城市地理信息包,然后上传到网站目录中进行调用。
It was not complicated, all I should do is downloading open source global cities geography data pack and uploading to my website directory.
具体调用语句比较简单
The data pack function is called by
[php]
$gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$ip);
[/php]
其中的$ip即已经获取到的访问者IP地址。调用后,需要的地址、经纬度、时区等信息从$record中提取即可。
$ip is the IP address fetched from visitor. The address, coordinate and time zone information can be picked out after the function is called.
其他内容并没有什么修改。
The other parts of the forecast core code has not been changed.
不过为了符合GoYuwei.Com的『双语』特征,多弄了个英文版界面。不过由于并非专业,还只能是中、英双语分为两个页面,这也提供了契机,下次可以学习php的多语种页面实现方法。
Pages are in Chinese&English and GoYuwei.Com is called ‘bilingual website’. I created a English version of the forecast. However, they are in two page files. There will be chance I can learn more about PHP and present the bilingual page in one web file.