如何调用免费API获取城市天气信息
1.先通过接口获取本机ip地址
http://pv.sohu.com/cityjson?ie=utf-8
如图:
2 .根据ip获取城市名
http://whois.pconline.com.cn/ipJson.jsp?callback=getCurrentCity&ip=${returnCitySN.cip}
如图:
此时调用方法就能看到返回信息了
window.getCurrentCity = function (res) {
this.cityName = res.city;
}
3.通过城市名获取天气信息
http://wthrcdn.etouch.cn/weather_mini?city=${this.cityName}
结果如图: