Wednesday 11 July 2012

Using Google Maps in a Flex / Flex + Google Map


Google Map API is available in For various Languages say for java script, Action Script
before we get started download Google API for Flex
Download Google API HERE : Download
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="100%" height="100%"
viewSourceURL="srcview/index.html">
<mx:Panel title="Google Maps Flash API Marker Creator Demo"
 backgroundColor="#FFFFFF" width="100%" height="100%"
 creationComplete="init();">

</mx:Panel>
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.services.ClientGeocoder;
import com.google.maps.services.GeocodingEvent;
import com.google.maps.services.GeocodingResponse;
import com.google.maps.services.Placemark;
import mx.controls.Alert;
import mx.events.ResizeEvent;
private var googleMap:Map;
private var geocoder:ClientGeocoder;
private function init():void {
googleMap = new Map();
googleMap.key = "ABQIAAAAvZMU4-DFRYtw1UlTj_zc6hT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQcT1h-VA8wQL5JBdsM5JWeJpukvw";
googleMap.addEventListener(MapEvent.MAP_READY, googleMap_mapReady);
googleMap.setSize(new Point(mapContainer.width, mapContainer.height));
googleMap.addControl(new ZoomControl());
googleMap.addControl(new MapTypeControl());
mapContainer.addChild(googleMap);
}
private function geocoder_geocodingSuccess(evt:GeocodingEvent):void {
var result:Placemark = GeocodingResponse(evt.response).placemarks[0];
googleMap.setCenter(result.point, 13);
}
private function geocoder_geocodingFailure(evt:GeocodingEvent):void {
Alert.show("Unable to geocode address: " + evt.name);
}
private function googleMap_mapReady(evt:MapEvent):void {
geocoder = new ClientGeocoder();
geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, geocoder_geocodingSuccess);
geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoder_geocodingFailure);
geocoder.geocode(textInput.text);
}
private function button_click(evt:MouseEvent):void {
geocoder.geocode(textInput.text);
}
private function mapContainer_resize(evt:ResizeEvent):void {
if (googleMap) {
googleMap.setSize(new Point(mapContainer.width, mapContainer.height));
}
}
]]>
</mx:Script>
<mx:String id="APP_ID" source="appid.txt" />
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="Address:"
direction="horizontal">
<mx:TextInput id="textInput"
 text="India,pune" />
<mx:Button id="button"
  label="Submit"
  click="button_click(event);" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:UIComponent id="mapContainer"
width="100%"
height="100%"
resize="mapContainer_resize(event);" />
</mx:Application>

No comments:

Post a Comment