Flash builder 4.5支持Android平台之初体验
Flash builder 4.5支持Android平台之初体验
2011年06月22日
Flash builder 4.5可以支持Android平台,俺尝试写了一些东西,算是第一次亲密接触。想法是这样的:将一些点的经纬度投射到Google Map上,并可浏览相关点的信息。 数据库使用MS SQL server 2008 R2 X64版本,创建数据表【Map201105】,该表描述点信息:
CREATETABLE[dbo].[Map201105](
[id][int]IDENTITY(1,1)NOTNULL,
[bianhao][int]NULL,
[zhengqibiaoshi][nvarchar](255)NULL,
[kehumingcheng][nvarchar](255)NULL,
[jiancheng][nvarchar](255)NULL,
[dengluyu][nvarchar](255)NULL,
[DVRtongdaohao][int]NULL,
[qianduangaicanshu][nvarchar](255)NULL,
[zhucedidian][nvarchar](255)NULL,
[zhushebeiID][nvarchar](255)NULL,
[jintouID][nvarchar](255)NULL,
[ADSL][nvarchar](255)NULL,
[GD163][nvarchar](255)NULL,
[GXSJ][nvarchar](255)NULL,
[BMQ][nvarchar](255)NULL,
[XSJ][nvarchar](255)NULL,
[CRMzhuangtai][nvarchar](255)NULL,
[tongduan][nvarchar](255)NULL,
[shigongfankui][nvarchar](255)NULL,
[xitonghuidanqingkuang][nvarchar](255)NULL,
[yanshou][nvarchar](255)NULL,
[beizhu][nvarchar](255)NULL,
[jingdu][float]NULL,
[weidu][float]NULL,
CONSTRAINT[PK_Map201105]PRIMARYKEYCLUSTERED
(
[id]ASC
)WITH (PAD_INDEX =OFF,STATISTICS_NORECOMPUTE =OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS =ON,ALLOW_PAGE_LOCKS =ON)ON[PRIMARY]
)ON[PRIMARY]
这里注意[jingdu]和[weidu]列,表示在GoogleMap上投点坐标,由于使用手持GPS测量数据使用度分秒表示,所有俺创建另外一个表记录这些测量的数据,【Maplatlng】,
CREATETABLE[dbo].[Maplatlng](
[id][int]IDENTITY(1,1)NOTNULL,
[Map110id][int]NULL,
[Lat][int]NULL,
[Lat_du][int]NULL,
[Lat_fen][int]NULL,
[Lat_miao][float]NULL,
[Lng][int]NULL,
[Lng_du][int]NULL,
[Lng_fen][int]NULL,
[Lng_miao][float]NULL,
CONSTRAINT[PK_Maplatlng]PRIMARYKEYCLUSTERED
(
[id]ASC
)WITH (PAD_INDEX =OFF,STATISTICS_NORECOMPUTE =OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS =ON,ALLOW_PAGE_LOCKS =ON)ON[PRIMARY]
)ON[PRIMARY]
GO
ALTERTABLE[dbo].[Maplatlng] WITHCHECKADD CONSTRAINT[FK_Maplatlng_Map201105]FOREIGNKEY([Map110id])
REFERENCES[dbo].[Map201105]([id])
GO
ALTERTABLE[dbo].[Maplatlng]CHECKCONSTRAINT[FK_Maplatlng_Map201105]
列[Map110id]是关联表【Map201105】外键。
使用Hibernate持久化数据,变成Java对象,Map201105映射文件:
Map201105">
Maplatlng映射文件:
map201105" fetch="select"> 从映射文件可以看出两个映射类之间的关系是多对一关系。
使用LCDS 3.1数据管理属性,配置文件data-management-config加入两个destination
com.les.Gmap.GMapAssembler
application
com.les.Gmap.Map201105
getOnArtist
java.lang.String,java.lang.Integer
com.les.Gmap.GMaplatlngAssembler
application
com.les.Gmap.Maplatlng
getOnArtist
java.lang.String,java.lang.Integer
第一个destination提供点的信息,特别是坐标信息,第二个destination提供经纬度数据
新建一个Flex手机项目,选定Android平台,选择"卡片式应用程序",一个卡片用于呈现地图,另一个呈现数据。
呈现Map的View:
flex/spark"
xmlns:components="spark.components.*"
xmlns:services="services.*"
xmlns:supportClasses="spark.skins.mobile.supportClasses.*"
creationComplete="application1_creationCompleteHan dler(event)" title="Map">
map:Map;
privatefunction onMapReady(event:Event):void {
this.map.addControl(new PositionControl());
this.map.addControl(new ZoomControl());
this.map.addControl(new ScaleControl());
for each (var _wx:Object in getOnArtistResult.lastResult){ //trace(_wx.jingdu); CreateSign(_wx.jiancheng,_wx.kehumingcheng,_wx.jin gdu,_wx.weidu); } } protectedfunction map_mapevent_mappreinitializeHandler(event:MapEven t):void { var myMapOptions:MapOptions = new MapOptions(); myMapOptions.zoom = 8; myMapOptions.center = new LatLng(23.0670,113.1370); myMapOptions.mapType = MapType.SATELLITE_MAP_TYPE; this.map.setInitOptions(myMapOptions); } privatefunction CreateSign(_jiancheng:String,_kehumingcheng:String ,_jingdu:Number,_weidu:Number):void { var markerA:Marker = new Marker(new LatLng(_jingdu,_weidu), new MarkerOptions({strokeStyle: new StrokeStyle({thickness: 1, color: 0xff8030, alpha: 0.7, pixelHinting: false}), fillStyle: new FillStyle({color: 0x223344, alpha: 0.8}), radius: 8, tooltip: _jiancheng, label:_kehumingcheng, hasShadow: true})); this.map.addOverlay(markerA); } protectedfunction application1_creationCompleteHandler(event:FlexEve nt):void { getOnArtistResult.token =map201105Service.getOnArtist('中国金名都', 0);
}
privatefunction listDataService_onselectresult(event:ResultEvent):void{
wx=ArrayCollection(event.result);
button01.enabled=true;
menucomment.text=wx[0].jiancheng;
map = new Map();
map.key = "Google Map key";
map.setSize(new Point(HDBox.width, HDBox.height));
map.sensor="false";
map.url="http://localhost";
map.addEventListener(MapEvent.MAP_READY, onMapReady);
map.addEventListener(MapEvent.MAP_PREINITIALIZE,ma p_mapevent_mappreinitializeHandler);
HDBox.addElement(map);
}
//处理错误函数 privatefunction onfault(event:FaultEvent):void{ trace(event.fault.faultString, 'Error'); } protectedfunction button01_clickHandler(event:Event):void { // TODO Auto-generated method stub if (textinput01.text!=''){ trace(textinput01.text); var str:String; str=textinput01.text; HDBox.removeElement(map); getOnArtistResult.token =map201105Service.getOnArtist(str, 0); button01.enabled=false; } } protectedfunction textinput01_focusInHandler(event:FocusEvent):void { // TODO Auto-generated method stub if (event.target.text=='输入建筑工地名称'){
event.target.text='';
}
}
protectedfunction textinput01_focusOutHandler(event:FocusEvent):void
{ // TODO Auto-generated method stub if (event.target.text==''){ event.target.text='输入建筑工地名称';
}
}
protectedfunction textinput01_textinputHandle(event:TextEvent):void
{ //event.target.setStyle('color',0x10DAA2); } protectedfunction combobox01_changeHandler(event:IndexChangeEvent):void { // TODO Auto-generated method stub trace(wx[event.newIndex].jintouId); var jingdu:Number; var weidu:Number; jingdu=wx[event.newIndex].jingdu; weidu=wx[event.newIndex].weidu; map.setCenter(new LatLng(jingdu,weidu)); map.setZoom(13); } ]]> 呈现数据的View:
flex/spark" xmlns:components="spark.components.*" xmlns:services="services.*" title="主页视图">
Mapview
DataView:
Flex文件比较大,生成地图时间约10秒。