Using google maps in flex

Wednesday, December 17, 2008
Basic requirements before using Google maps (assuming you already have flex builder)

1. Get GoogleMaps API SDK
2. Sign up for API Key

Follow these steps

3. Open flex builder
4. Create new web project
5. Add reference of map_flex_1_8b.swc to the project




6. Add mxml code


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="com.google.maps.controls.*">
<maps:Map url="http://www.yoururl.com/" xmlns:maps="com.google.maps.*" id="myMap" mapevent_mapready="onMapReady(event)" width="100%" height="100%" key="yourkey"/>
<mx:Button label="Current Lat Long" click="ShowLatLong()" x="10" y="10"/>
<mx:Button label="++" width="50" click="zoomIn()" x="10" y="40"/>
<mx:Button label="--" width="50" click="zoomOut()" x="10" y="238"/>
<mx:VSlider id="vsZoom" x="28" y="70" minimum="1" maximum="17" tickInterval="0.1" change="zoomChange()"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;

private function onMapReady(event:Event):void {
init();
myMap.setCenter(new LatLng(17.7345444917096,83.32132062557982),vsZoom.value, MapType.NORMAL_MAP_TYPE);
//click not working - but by default it handles
//myMap.addEventListener(MouseEvent.DOUBLE_CLICK,handleMouseClick);
myMap.addEventListener(MouseEvent.MOUSE_WHEEL,handleMouseWheel);
}
private function ShowLatLong():void{
var objLatLong:LatLng;
objLatLong = myMap.getCenter();
myMap.zoomIn();
Alert.show("[lat]"+objLatLong.lat()+ "[long]"+objLatLong.lng());
}
private function zoomIn():void{
vsZoom.value = vsZoom.value + 1;
zoomChange();
}
private function zoomOut():void{
vsZoom.value = vsZoom.value - 1;
zoomChange();
}
private function init():void{
vsZoom.value = vsZoom.maximum;
}
private function zoomChange():void{
myMap.setZoom(vsZoom.value);
}
private function handleMouseClick():void{
vsZoom.value = vsZoom.value + 1;
}
private function handleMouseWheel(ev:MouseEvent):void{
vsZoom.value = vsZoom.value + ev.delta/30;
zoomChange();
}
]]>
</mx:Script>

</mx:Application>




7. Change url and apikey to your values

sample output




Madhu :-)

Labels:

 
posted by madhu at 7:47 PM, | 0 comments

Checking user is idle or not in AIR

This changes the label according to user is active or idle on system.
Please note this is for AIR only.


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute">
<mx:Script>
<![CDATA[
private function init():void
{
NativeApplication.nativeApplication.idleThreshold = 5;

NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, userActiveAlert);

NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, userIdleAlert);

}
private function userActiveAlert(ev:Event):void
{
lblUserStatus.text = "User came back :-)";
lblUserStatus.setStyle("color",StyleManager.getColorName("green"));
}
private function userIdleAlert(ev:Event):void
{
lblUserStatus.text = "User is idle :-(";
lblUserStatus.setStyle("color",StyleManager.getColorName("red"));
}
]]>
</mx:Script>
<mx:Label id="lblUserStatus" />
</mx:WindowedApplication>

Labels:

 
posted by madhu at 6:01 PM, | 0 comments

Maximising an air application on startup

Tuesday, December 2, 2008
Maximising an air application on startup

dont forgot to use in applicationComplete


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
applicationComplete="onApplicationComplete();">

<mx:Script>
<![CDATA[

private function onApplicationComplete():void {
stage.nativeWindow.maximize();
}

]]>
</mx:Script>

</mx:WindowedApplication>


Madhu :)
 
posted by madhu at 12:39 PM, | 0 comments