I created a class that might help you load KML from a remote server into
Google Maps in Flex. Here's the post (entitled GoogleMapKMLLoader for Flash
Builder 4):

http://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/94a36bff1f51bbc0/91018d3b3a1ba60c?pli=1

It simplifies the process quite a bit, I think.

Best regards,
Jeff Smith

On Wed, Sep 15, 2010 at 9:36 PM, <
[email protected]<google-maps-api-for-flash%[email protected]>
> wrote:

>   Today's Topic Summary
>
> Group: http://groups.google.com/group/google-maps-api-for-flash/topics
>
>    - Optimize waypoints? <#12b189d17770a5c1_group_thread_0> [1 Update]
>    - How to draw rectangle over google map using 
> flex<#12b189d17770a5c1_group_thread_1>[3 Updates]
>    - Exception when re- loading the google 
> map<#12b189d17770a5c1_group_thread_2>[1 Update]
>    - Loading KML from a remote server into the Flash 
> API<#12b189d17770a5c1_group_thread_3>[2 Updates]
>
>   Topic: Optimize 
> waypoints?<http://groups.google.com/group/google-maps-api-for-flash/t/45405fa96ebbb888>
>
>    rzumbado <[email protected]> Sep 15 02:44PM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    Hi there,
>
>    is there an easy way to optimize the waypoings using the Directions
>    class?
>    I know there is a loadFromWaypoints(waypoints:Array) method, however,
>    this method does not optimize the route.
>
>    I know the javascript API does optimize the route:
>
>    ------------------------------------- START
>
>    
> ----------------------------------------------------------------------------------------
>
>    
> http://code.google.com/apis/maps/documentation/javascript/services.html#Waypoints
>
>    
> -----------------------------------------------------------------------------------------------------------------------------------------
>    By default, the Directions service calculates a route through the
>    provided waypoints in their given order. Optionally, you may pass
>    optimizeWaypoints: true within the DirectionsRequest to allow the
>    Directions service to optimize the provided route by rearranging the
>    waypoints in a more efficient order. (This optimization is an
>    application of the Travelling Salesman Problem.) All waypoints must be
>    stopovers for the Directions service to optimize their route.
>    ------------------------------------- END
>
>    
> -------------------------------------------------------------------------------------------
>
>    Is there any way to do that at all using the actionscript API? or
>    perhaps an extension class or something?
>
>    Many Thanks!
>
>
>
>   Topic: How to draw rectangle over google map using 
> flex<http://groups.google.com/group/google-maps-api-for-flash/t/d20ee17c090203e4>
>
>    Ashutosh <[email protected]> Sep 15 04:31AM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    I like to draw a rectangle over google map using flex. User needs to
>    click on map, so map click point is the starting point of rectangle
>    and as mouse moves over map rectangle gets bigger. on double click,
>    rectangle creation completed.
>
>    Can anyone help on this using google flex apis. I am stuck on this.
>
>    Thanks in advance.
>
>
>
>
>    Elisheva <[email protected]> Sep 15 10:53AM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    Take a look at this demo source
>
>
>    
> http://gmaps-samples-flash.googlecode.com/svn/trunk/demos/ResizingSmartInfoWindow/ResizingSmartInfoWindow.html
>
>    You can draw the rect in the program and then listen for the next
>    events...
>
>    Hope this helps
>
>    Elisheva
>
>
>
>
>
>    Bruce Ralston <[email protected]> Sep 15 02:57PM -0400 
> ^<#12b189d17770a5c1_digest_top>
>
>    Anther good example is
>    http://blog.jeethukarthik.com/flex-selection-rectangle/
>
>
>    --
>    Bruce Ralston
>    Professor
>    Department of Geography
>    University of Tennessee
>    Knoxville, TN 37996-0925
>    Phone: 865-974-6043
>    FAX: 865-974-6025
>
>
>
>   Topic: Exception when re- loading the google 
> map<http://groups.google.com/group/google-maps-api-for-flash/t/2d682e8976c03258>
>
>    sai <[email protected]> Sep 15 10:31AM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    Ive loaded the map. now i close it and load it again. I gt this
>    exception.
>
>
>    Error: Object not initialized
>    at com.google.maps.wrappers::Wrapper$/checkValid()
>    at com.google.maps.wrappers::IMapWrapper/addControl()
>    at com.google.maps::Map/addControl()
>    at com.greenclinical.gcs.fe.view.frontdesk::GoogleMapDemographics/
>    init()[C:\Users\Sai\Desktop\GreenClinical\Dev\Workspace\Gcs-Web\src\com
>    \greenclinical\gcs\fe\view\frontdesk\GoogleMapDemographics.mxml:85]
>    at com.greenclinical.gcs.fe.view.frontdesk::GoogleMapDemographics/
>    ___GoogleMapDemographics_TitleWindow1_creationComplete()[C:\Users\Sai
>    \Desktop\GreenClinical\Dev\Workspace\Gcs-Web\src\com\greenclinical\gcs
>    \fe\view\frontdesk\GoogleMapDemographics.mxml:12]
>    at flash.events::EventDispatcher/dispatchEventFunction()
>    at flash.events::EventDispatcher/dispatchEvent()
>    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects
>    \framework\src\mx\core\UIComponent.as:12528]
>    at mx.core::UIComponent/set initialized()[E:\dev\4.x\frameworks
>    \projects\framework\src\mx\core\UIComponent.as:1627]
>    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x
>    \frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
>    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev
>    \4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:
>    1072]
>
>
>
>    ************************CODE***********************************
>
>
>    <?xml version="1.0" encoding="utf-8"?>
>    <mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009";
>    xmlns:s="library://ns.adobe.com/flex/spark"
>    xmlns:mx="library://ns.adobe.com/flex/mx"
>    width="850"
>    height="650"
>    creationComplete="init()"
>    showCloseButton="true"
>    close="closePopUp()"
>    backgroundAlpha="1"
>    paddingLeft="10"
>    layout="vertical">
>    <fx:Declarations>
>    <!-- Place non-visual elements (e.g., services, value objects) here
>    -->
>    </fx:Declarations>
>    <fx:Script>
>    <![CDATA[
>    import com.google.maps.InfoWindowOptions;
>    import com.google.maps.LatLng;
>    import com.google.maps.Map;
>    import com.google.maps.MapEvent;
>    import com.google.maps.MapMouseEvent;
>    import com.google.maps.MapOptions;
>    import com.google.maps.controls.MapTypeControl;
>    import com.google.maps.controls.PositionControl;
>    import com.google.maps.controls.ZoomControl;
>    import com.google.maps.overlays.Marker;
>    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
>    com.greenclinical.gcs.fe.model.managers.AuthenticationManager;
>    import com.greenclinical.gcs.fe.model.valueObjects.Address;
>    import com.greenclinical.gcs.fe.model.valueObjects.UsersLocation;
>    import com.greenclinical.gcs.fe.view.frontdesk.google.PharmacyVO;
>    import
>    com.greenclinical.gcs.fe.view.frontdesk.google.components.InputBox;
>    import
>    com.greenclinical.gcs.fe.view.frontdesk.google.components.InputBox1;
>    import
>    com.greenclinical.gcs.fe.view.frontdesk.google.components.MapOverlay;
>    import
>    com.greenclinical.gcs.fe.view.frontdesk.google.components.MarkerData;
>    import
>
>    
> com.greenclinical.gcs.fe.view.frontdesk.google.events.InfoWindowClosedEvent;
>    import
>    com.greenclinical.gcs.fe.view.frontdesk.google.utils.MapUtils;
>
>    import mx.collections.ArrayCollection;
>    import mx.containers.VBox;
>    import mx.controls.Alert;
>    import mx.events.ResizeEvent;
>    import mx.managers.PopUpManager;
>    import mx.rpc.events.FaultEvent;
>    import mx.rpc.events.ResultEvent;
>    import mx.rpc.http.HTTPService;
>
>    private var googleMap:Map;
>    private var geocoder:ClientGeocoder;
>    private var
>
>    
> locId:int=AuthenticationManager.getInstance().currentLoggedInUser.location.locationId;
>
>    [Bindble]
>    private var zip:String;
>    [Bindable]
>    private var _acGeocoderList:ArrayCollection;
>    [Bindable]
>    public var dataProvider:ArrayCollection = new ArrayCollection();
>
>    private var _callBackFunc:Function;
>
>    private function closePopUp():void
>    {
>    PopUpManager.removePopUp(this);
>    }
>
>    public function set callBackFunc(func:Function):void{
>    _callBackFunc = func;
>    }
>
>    public function get callBackFunc():Function{
>    return _callBackFunc
>    }
>
>    private function init():void
>    {
>    PopUpManager.centerPopUp(this);
>    googleMap=new Map();
>    googleMap.key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-
>    iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g"; //APP_ID;
>    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);
>    for each (var add:UsersLocation in
>
>    
> AuthenticationManager.getInstance().currentLoggedInUser.users.usersLocations
>    as ArrayCollection)
>    {
>    if (locId == add.location.locationId)
>    {
>    zip=add.location.address.zip;
>    textInput.text=zip;
>    break;
>    }
>    }
>
>    }
>
>    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(String(zip));
>    }
>
>    private function button_click(evt:MouseEvent):void
>    {
>    // TODO should change ths for real data
>    var httpCall:HTTPService;
>    for each (var obj:Object in MapUtils.getMapAddress())
>    {
>    httpCall = new HTTPService();
>    httpCall.resultFormat="e4x";
>    httpCall.addEventListener(ResultEvent.RESULT, onGoogleResult);
>    httpCall.addEventListener(FaultEvent.FAULT, onGoogleFault);
>
>    httpCall.url="http://maps.google.com/maps/api/geocode/xml?
>    address=" + obj.address +"&sensor=true&pharmacyId="+obj["pharmacyId"];
>    httpCall.send(obj);
>    }
>    geocoder.geocode(textInput.text);
>    }
>
>    private function onGoogleResult(evt:ResultEvent):void
>    {
>    var xData:XML = XML(evt.result);
>    var md:MarkerData = new
>
>    
> MarkerData(Number(xData.result.geometry.location.lat),Number(xData.result.geometry.location.lng),
>
>
>    
> String(xData.result.formatted_address),String(xData.result.formatted_address),
>
>    getPharmacyVoFromPharmacyId(getPharmacyIdFromUrl(evt.target["url"])));
>    var latlng:LatLng = new
>
>    
> LatLng(Number(xData.result.geometry.location.lat),Number(xData.result.geometry.location.lng));
>    var marker:Marker= new Marker(latlng);
>    addMarker(md,marker);
>    }
>
>    private function
>    getPharmacyIdFromUrl(url:String,compareString:String=
>    "pharmacyId"):String{
>    var params:Array = url.split("&");
>    var prop:Array ;
>    for each(var string:String in params){
>    prop = string.split("=")
>    if(prop[0] == compareString){
>    return prop[1];
>    }
>    }
>    return "";
>    }
>
>    private function
>    getPharmacyVoFromPharmacyId(pharmacyId:String):Object{
>    for each(var obj:Object in MapUtils.getMapAddress()){
>    if(obj["pharmacyId"] == int(pharmacyId)){
>    return obj;
>    }
>    }
>    return null;
>    }
>
>    public function addMarker(markerData:MarkerData,
>    marker:Marker):void{
>    var o:Object = {markerData:markerData,marker:marker};
>    marker.addEventListener(MapMouseEvent.ROLL_OVER,markerMouseOver);
>    marker.addEventListener(MapMouseEvent.CLICK,markerClicked);
>    marker.addEventListener(InfoWindowClosedEvent.NAME,closed);
>    markerData.marker = marker;
>    googleMap.addOverlay(marker);
>    dataProvider.addItem(o);
>    dataProvider.refresh();
>    }
>
>    private function onGoogleFault(evt:FaultEvent):void
>    {
>
>    }
>
>    public function markerClicked(event:MapMouseEvent):void{
>    var marker:Marker = event.target as Marker;
>    var o:Object =
>
>    
> MapUtils.getMarkerDataByLatAndLng(marker.getLatLng().lat(),marker.getLatLng().lng(),dataProvider);
>    if (o != null){
>    callBackFunc(o);
>    }
>    closePopUp();
>    }
>
>    public function markerMouseOver(event:MapMouseEvent):void{
>    var marker:Marker = event.target as Marker;
>    var overlay:InputBox1 = new InputBox1();
>
>    //overlay.marker=marker;
>    var o:Object =
>
>    
> MapUtils.getMarkerDataByLatAndLng(marker.getLatLng().lat(),marker.getLatLng().lng(),dataProvider);
>    /* overlay.address.text = (o["markerData"] as
>    MarkerData).pharmacyVo["address"];
>    overlay.heading.text = (o["markerData"] as
>    MarkerData).pharmacyVo["pharmacyName"]; */
>    if (o != null){
>    //inputBox = o["markerData"].name;
>    marker.openInfoWindow(new
>    InfoWindowOptions({contentHTML:getHtmlContent(o),
>    width:200,height:100,drawDefaultFrame:true}));
>    }
>    }
>
>
>    private function getHtmlContent(o:Object):String{
>    var data:MarkerData = o["markerData"];
>    var content:String = "<b><font
>    size='14'>"+data.pharmacyVo["pharmacyName"] + "</font>" +
>    "<br/><br/><p>"+ data.address+"</p>";
>    content += "<br/><br/><font size ='8'>" + "*Please click on the
>    bubble to save it into the patients favourites" +"</font>";
>    return content;
>    }
>
>    /* public function createMyCustomContent():VBox {
>    var myVbox:VBox = new VBox();
>    var titleTextField:TextInput = new TextInput();
>    titleTextField.text = "This is the title";
>    myVbox.addChild(titleTextField);
>    return myVbox;
>    }
>    */
>    public function closed(event:InfoWindowClosedEvent):void{
>    /* var marker:Marker = event.marker;
>    var latLng:LatLng = marker.getLatLng();
>    var markerData:MarkerData = new
>    MarkerData(latLng.lat(),latLng.lng(),event.inputName);
>    var o:Object =
>
>    MapUtils.getMarkerDataByLatAndLng(latLng.lat(),latLng.lng(),dataProvider);
>    if (o == null){
>    addMarker(markerData,marker);
>    }else{
>    o["markerData"] = markerData;
>    dataProvider.refresh();
>    } */
>    }
>
>    private function mapContainer_resize(evt:ResizeEvent):void
>    {
>    if (googleMap)
>    {
>    googleMap.setSize(new Point(mapContainer.width,
>    mapContainer.height));
>    }
>    }
>    ]]>
>    </fx:Script>
>    <s:HGroup width="100%" height="30">
>    <mx:FormItem label="Address:"
>    direction="horizontal">
>    <mx:TextInput id="textInput"/>
>    <mx:Button id="button"
>    label="Submit"
>    click="button_click(event);"/>
>    </mx:FormItem>
>    </s:HGroup>
>    <mx:HBox width="100%" height="100%">
>    <mx:UIComponent id="mapContainer"
>    width="100%"
>    height="100%"
>    resize="mapContainer_resize(event);"/>
>    <mx:Panel width="200" height="100%">
>
>    </mx:Panel>
>    </mx:HBox>
>    </mx:TitleWindow>
>
>
>
>   Topic: Loading KML from a remote server into the Flash 
> API<http://groups.google.com/group/google-maps-api-for-flash/t/6dc917ab94aa71b6>
>
>    mic <[email protected]> Sep 14 09:12PM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    It's actually built on the Parser by Pamela, it uses the parser to
>    interpret the kml and then creates the appropriate overlay objects to
>    add to a Map instance
>
>    To setup a proxy you'll have to have a server you control. Then write
>    a small script that basically loads the kml file from the server and
>    echoes the data back. On this server you'll place a crossdomain.xml
>    file allowing your swf access to the script.
>
>    so you'll then pass the location of this proxy to your kml loader:
>
>    http://address.of.server/proxy.script?url=original-kml-file-url
>
>    There are many examples to create these proxy scripts on the net, but
>    they depend on the type of server etc.
>
>    eg: php script: http://www.daniweb.com/code/snippet216729.html
>
>    Hope that helps,
>    Michael
>
>
>
>
>
>    Tw1nkie <[email protected]> Sep 15 10:32AM -0700 
> ^<#12b189d17770a5c1_digest_top>
>
>    I will give the proxy solution a look, thank you!
>
>    One last question if I may, how are you dealing with KMZ?
>
>    Cheers,
>    Nate
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API For Flash" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api-for-flash%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api-for-flash?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en.

Reply via email to