最近在研究yahoo的天气api。
挺好用的,不过返回数据都是英文。网上找了中英文对照。稍后放详细开发教程。
源码放出。在开发中有几个问题这里重点提一下。
第一 关于数字显示。比如9点 从美观上考虑需要 加上0 显示为 09:01分。这样会好看。则需要对比系统时间 当小于10的时候String 然后前边加上0.月份和日期做相同处理。
当flash加载yahoo的图片时候。跨预加载有时候本地会不现实。在loader中添加一个LoaderContext 即可。
如下:
var isr:String = o.imageURL;
//trace(isr);
var iid:Array = isr.match(/[0-9]./g);
var lo:Loader=new Loader();
var lc:LoaderContext = new LoaderContext(true);
lo.load(new URLRequest(“http://l.yimg.com/a/i/us/nws/weather/gr/”+iid[1]+”d.png”),lc);
lo.contentLoaderInfo.addEventListener(Event.COMPLETE,showit);
需要说明的是 yahoo返回的数据中默认的图片是一种很小的gif。
如图:
我个人喜欢加载那个大png透明图。
通过正则获得接口返回的图片编号,然后加载对应的png。
注意上边那个范例就是如此处理的。
han = new Array();
han.push( { label:’AM Clouds / PM Sun’,name:’上午有云/下午后晴 ‘ } );
han.push( { label:’AM Showers’,name:’上午阵雨 ‘ } );
han.push( { label:’AM Snow Showers’,name:’上午阵雪’ } );
han.push( { label:’AM Thunderstorms’,name:’上午雷暴雨 ‘ } );
han.push( { label:’Clear’,name:’晴朗 ‘ } );
han.push( { label:’Cloudy’,name:’多云 ‘ } );
han.push( { label:’Cloudy / Wind’,name:’阴时有风’ } );
han.push( { label:’Clouds Early / Clearing Late’,name:’早多云/晚转晴’ } );
han.push( { label:’Drifting Snow’,name:’飘雪 ‘ } );
han.push( { label:’Drizzle’,name:’毛毛雨 ‘ } );
han.push( { label:’Dust’,name:’灰尘 ‘ } );
han.push( { label:’Fair’,name:’晴 ‘ } );
han.push( { label:’Few Showers’,name:’短暂阵雨 ‘ } );
han.push( { label:’Few Snow Showers’,name:’短暂阵雪 ‘ } );
han.push( { label:’Few Snow Showers / Wind’,name:’短暂阵雪时有风 ‘ } );
han.push( { label:’Fog’,name:’雾 ‘ } );
han.push( { label:’Haze’,name:’薄雾 ‘ } );
han.push( { label:’Hail’,name:’冰雹 ‘ } );
han.push( { label:’Heavy Rain’,name:’大雨’ } );
han.push( { label:’Heavy Rain Icy’,name:’大冰雨 ‘ } );
han.push( { label:’Heavy Snow’,name:’大雪 ‘ } );
han.push( { label:’Heavy Thunderstorms’,name:’强烈雷雨 ‘ } );
han.push( { label:’Isolated Thunderstorms’,name:’局部雷雨 ‘ } );
han.push( { label:’Light Drizzle’,name:’微雨 ‘ } );
han.push( { label:’Light Rain’,name:’小雨 ‘ } );
han.push( { label:’Light Rain Shower’,name:’小阵雨 ‘ } );
han.push( { label:’Light Rain Shower and Windy’,name:’小阵雨带风’ } );
han.push( { label:’Light Rain with Thunder’,name:’小雨有雷声 ‘ } );
han.push( { label:’Light Snow’,name:’小雪 ‘ } );
han.push( { label:’Light Snow Fall’,name:’小降雪 ‘ } );
han.push( { label:’Light Snow Grains’,name:’小粒雪 ‘ } );
han.push( { label:’Light Snow Shower’,name:’小阵雪 ‘ } );
han.push( { label:’Lightening’,name:’雷电 ‘ } );
han.push( { label:’Mist’,name:’薄雾 ‘ } );
han.push( { label:’Mostly Clear’,name:’大部晴朗 ‘ } );
han.push( { label:’Mostly Cloudy’,name:’大部多云 ‘ } );
han.push( { label:’Mostly Cloudy/ Windy’,name:’多云时阴有风 ‘ } );
han.push( { label:’Mostly Sunny’,name:’晴时多云 ‘ } );
han.push( { label:’Partly Cloudy’,name:’局部多云 ‘ } );
han.push( { label:’Partly Cloudy/ Windy’,name:’多云时有风 ‘ } );
han.push( { label:’PM Rain / Wind’,name:’下午小雨时有风 ‘ } );
han.push( { label:’PM Light Rain’,name:’下午小雨 ‘ } );
han.push( { label:’PM Showers’,name:’下午阵雨 ‘ } );
han.push( { label:’PM Snow Showers’,name:’下午阵雪 ‘ } );
han.push( { label:’PM Thunderstorms’,name:’下午雷雨 ‘ } );
han.push( { label:’Rain’,name:’雨 ‘ } );
han.push( { label:’Rain Shower’,name:’阵雨 ‘ } );
han.push( { label:’Rain Shower/ Windy’,name:’阵雨/有风 ‘ } );
han.push( { label:’Rain / Snow Showers’,name:’雨或阵雪 ‘ } );
han.push( { label:’Rain / Snow Showers Early’,name:’下雨/早间阵雪 ‘ } );
han.push( { label:’Rain / Wind’,name:’雨时有风 ‘ } );
han.push( { label:’Rain and Snow’,name:’雨夹雪 ‘ } );
han.push( { label:’Scattered Showers’,name:’零星阵雨 ‘ } );
han.push( { label:’Scattered Showers / Wind’,name:’零星阵雨时有风 ‘ } );
han.push( { label:’Scattered Snow Showers’,name:’零星阵雪 ‘ } );
han.push( { label:’Scattered Snow Showers / Wind’,name:’零星阵雪时有风 ‘ } );
han.push( { label:’Scattered Strong Storms’,name:’零星强烈暴风雨 ‘ } );
han.push( { label:’Scattered Thunderstorms’,name:’零星雷雨 ‘ } );
han.push( { label:’Showers’,name:’阵雨 ‘ } );
han.push( { label:’Showers Early’,name:’早有阵雨 ‘ } );
han.push( { label:’Showers Late’,name:’晚有阵雨 ‘ } );
han.push( { label:’Showers / Wind’,name:’阵雨时有风 ‘ } );
han.push( { label:’Showers in the Vicinity’,name:’周围有阵雨 ‘ } );
han.push( { label:’Smoke’,name:’烟雾 ‘ } );
han.push( { label:’Snow’,name:’雪 ‘ } );
han.push( { label:’Snow / Rain Icy Mix’,name:’冰雨夹雪 ‘ } );
han.push( { label:’Snow and Fog’,name:’雾夹雪 ‘ } );
han.push( { label:’Snow Shower’,name:’阵雪 ‘ } );
han.push( { label:’Snowflakes’,name:’雪花 ‘ } );
han.push( { label:’Sunny’,name:’晴朗 ‘ } );
han.push( { label:’Sunny / Wind’,name:’晴时有风 ‘ } );
han.push( { label:’Sunny Day’,name:’晴天 ‘ } );
han.push( { label:’Thunder’,name:’雷鸣 ‘ } );
han.push( { label:’Thunder in the Vicinity’,name:’周围有雷雨 ‘ } );
han.push( { label:’Thunderstorms’,name:’雷雨 ‘ } );
han.push( { label:’Thunderstorms Early’,name:’早有持续雷雨 ‘ } );
han.push( { label:’Thunderstorms Late’,name:’晚有持续雷雨 ‘ } );
han.push( { label:’Windy’,name:’有风 ‘ } );
han.push( { label:’Windy / Snowy’,name:’有风/有雪 ‘ } );
han.push( { label:’Windy Rain’, name:’刮风下雨 ‘ } );
han.push( { label:’Wintry Mix’, name:’雨雪混合’ } );