Question

Still pretty new to Flex. I'm trying to incorporate the Google Maps JavaScript API into my Flex application while pulling the marker data from a database via ColdFusion.

The application is supposed to pull all the students who attend a particular school and then display the students via markers on the map. It's also supposed to display the school, but I haven't gotten to that yet.

I have most of it written but I'm stuck on what may end up being a simple part. I have the map created, and I have the CFC pulling the coordinate data but then I get errors when I try to return the data back to the action script page.

I'm getting "The value returned from the getGeoInfo function is not of type Query." I realize that maybe I'm using the wrong returntype, but I'm not sure what else to use.

Here is an example of what the CFC is returning.

28.5980179,-81.3651601;28.5383355,-81.3792365 

Here are my actionscript functions for getting the geographical locations:

/** getGeoInfo
* get the Geographical Data
*
* @param void
* @return void
*/

private function getGeoInfo():void
{
    try
    { 
        var myArgs:Object = new Object;
        /* myArgs.column_list = "GeoCode, Student_Address, Student_Name_First, Student_Name_Last"; */
        remotingDelegate.callCFC("getGeoInfo", myArgs);
    }

    catch (error:Error)
    {
        FlexException.errorHandler(error, "StudentPopMapModuleCode:getGeoInfo");
    }
}


/**
* getGeoInfo_Handler
* The handler of the remoting call    
* @param Object results The results of the remoting call
* @return void
*/

public function getGeoInfo_Handler(results:ArrayCollection):void
{
    try
    { 
        geoInfoAC = results;
    }

    catch (error:Error)
    {
    FlexException.errorHandler(error, "StudentPopMapModuleCode:getGeoInfo_Handler");
    }
} 

and here is the code on the mxml page to receive the coordinates:

public function onMapReady(event:MapEvent):void {
    map.setCenter(new LatLng(37.4419, -122.1419), 13, MapType.NORMAL_MAP_TYPE);
    for each (var o:Object in geoInfoAC){
        var md:MarkerData = o["markerData"] as MarkerData;
        var latlng:LatLng = new LatLng(md.lat,md.lng);
        var marker:Marker= new Marker(latlng);
        addMarker(md,marker); 
    }
}

public function addMarker(markerData:MarkerData, marker:Marker):void{
    var o:Object = {markerData:markerData,marker:marker};
    marker.addEventListener(MapMouseEvent.CLICK,markerClicked);
    marker.addEventListener(InfoWindowClosedEvent.NAME,closed);
    markerData.marker = marker;
    map.addOverlay(marker);
    dataProvider.addItem(o); 
    dataProvider.refresh(); 
}

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();
    }
} 

Any help would be greatly appreciated.

Was it helpful?

Solution

Turns out that because it was being treated as a string, I needed to split the array by each coordinate. I used the following and it worked.

The handler was updated to:

public function getGeoInfo_Handler(results:String):void { 
try { geoInfoAC = new ArrayCollection(results.split(";")); 

Then on the actual mxml page I used:

public function onMapReady(event:MapEvent):void { 
map.setCenter(new LatLng(28.5383355,-81.3792365), 11, MapType.NORMAL_MAP_TYPE); 
for each (var o:Object in geoInfoAC){
var latlngArray:Array = o.split(","); 
var md:MarkerData = new MarkerData(latlngArray[0],latlngArray[1]); 
var latlng:LatLng = new LatLng(md.lat,md.lng); 
var marker:Marker= new Marker(latlng); addMarker(md,marker);

Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top