flex actionscript multiple markers markers not matching tooltip or lat lng

I had this same issue when I created an application using google's javascript API and the solution was to have closure on the callback function creating the multiple markers.

I can not seem to find an example for making multiple custom markers, with anything other than using some random math function to create the multiple markers.

GlobalVars is a class that contains static public var types to keep up with however many addressess, lats, lngs, etc...

I have tried using markermanager but it has some issues that I finally just gave up on.

Starting with

 retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{

This is where I begin geocoding by address, rather than using an httpservice, as I was doing before, but I ran into issues of one httpservice result would return faster than another, which would in turn place the wrong data with the wrong marker.

Obviously, I have not found a solution, because this way is doing the same thing.

Question being, how can I retrieve multiple markers info and keep all the markeroptions in order with the information being returned.

Here's the code:

            public function makeMultipleMarkers(destinationAllObj:Object):void {
            removeRouteMarkers();
            myMarkers = [];
            GlobalVars.myIcon = [];
            GlobalVars.someAddress = [];
            GlobalVars.sName = [];

            markerMgr.clearMarkers();
            GlobalVars.destinationInc = 0;

            retrieveLatLngAddress = new ClientGeocoder();
            retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{
                var result:Placemark = GeocodingResponse(event.response).placemarks[0];
                var latLngStr:String = result.point.toString();
                GlobalVars.panoLatLng = latLngStr.split(',');
                var deleteLeftParen:String = GlobalVars.panoLatLng[0];
                GlobalVars.panoLatLng[0] = deleteLeftParen.replace("(","");
                var deleteRightParen:String = GlobalVars.panoLatLng[1];
                GlobalVars.panoLatLng[1] = deleteRightParen.replace(")","");
                bounds = new LatLngBounds();


                var request:URLRequest = new URLRequest(GlobalVars.myIcon[GlobalVars.destinationInc]);
                var imageLoader:Loader = new Loader();
                imageLoader.load(request);
                imageLoader.name = String(GlobalVars.myIcon[GlobalVars.destinationInc]);

                // Alert.show(GlobalVars.panoLatLng[0]);
                var tmpLatLng:LatLng = new LatLng(GlobalVars.panoLatLng[0], GlobalVars.panoLatLng[1]);
                someMarker = new Marker(tmpLatLng, new MarkerOptions({
                    icon: imageLoader,
                    tooltip: destinationAllObj[GlobalVars.destinationInc].SNAME+', '+GlobalVars.someAddress[GlobalVars.destinationInc],
                    hasShadow: false
                }));

                someMarker.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void{
                    var marker:Marker = event.target as Marker;
                    var markerContent:String = marker.getOptions().tooltip.toString();
                    textInput.text = marker.getOptions().tooltip.toString();
                    marker.openInfoWindow(new InfoWindowOptions({content: markerContent}));

                    sendSomeLatLngToSv(event.latLng);

                    var lastIndexOfDashStr:String = marker.getOptions().icon.name;

                    GlobalVars.iconObj = lastIndexOfDashStr;
                    var tmpArr:Array = new Array;
                    var tmpStr:String = event.currentTarget.getOptions().tooltip;
                    tmpArr = tmpStr.split(',');
                    GlobalVars.panoAddr[0] = tmpArr[1];
                    GlobalVars.sName[0] = tmpArr[0];
                });

                myMarkers.push(someMarker);
                googleMap.addOverlay(someMarker);

                for each(someMarker in myMarkers)
                {
                    var newLatLng:LatLng = someMarker.getLatLng();
                    bounds.extend(newLatLng);
                }

                GlobalVars.destinationInc++;

                if(GlobalVars.newDestObj.length == GlobalVars.destinationInc)
                {
                    statusTxt.text = "Complete";
                    googleMap.setCenter(bounds.getCenter(), (googleMap.getBoundsZoomLevel(bounds))-2, MapType.HYBRID_MAP_TYPE);

                    // markerMgr.addMarkers(myMarkers, 8, 16);
                    // markerMgr.refresh();
                }
            });
            retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoderMarkersFailure);


            for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
            {
                // Alert.show(destinationAllObj[GlobalVars.destinationCounter].ICON);
                GlobalVars.someAddress[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].SLOC;
                GlobalVars.sName[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].SNAME;

                if(destinationAllObj[GlobalVars.destinationCounter].ICON == "")
                {
                    GlobalVars.myIcon[GlobalVars.destinationCounter] = "images/school_32.png";
                    // Alert.show(GlobalVars.destinationCounter+" "+GlobalVars.myIcon[GlobalVars.destinationCounter]);
                }
                else
                {
                    GlobalVars.myIcon[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].ICON;
                }

                statusTxt.text = "Processing data, please wait...";
            }

            for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
            {
                var tempURL:String = "http://kronusproductions.com/mycarpaysme_ajax/php/google_lat_lng_flex_lausd.php?addr="+destinationAllObj[GlobalVars.destinationCounter].SLOC;

                // loadMyXml(tempURL);

                retrieveLatLngAddress.geocode(destinationAllObj[GlobalVars.destinationCounter].SLOC);
                statusTxt.text = "Processing data, please wait...";
            }
        }

Answers


OK, I did three things to make this work properly.

First, I wrote only one for loop.

Second, I call the makeMultipleMarkers function a second time after three seconds passed.

Third, if I still receive a status code of 500, then I send a request to google until I do not receive a status code of 500.

        public function makeMultipleMarkers(destinationAllObj:Object):void {
            myMarkers = [];
            GlobalVars.myIcon = [];
            GlobalVars.someAddress = [];
            GlobalVars.sName = [];
            GlobalVars.destinationInc = 0;

            googleMap.getPaneManager().clearOverlays();

            bounds = new LatLngBounds();
            retrieveLatLngAddress = new ClientGeocoder();

            retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{
                var result:Placemark = GeocodingResponse(event.response).placemarks[0];
                var latLngStr:String = result.point.toString();
                // GlobalVars.statusCode = event.status;

                var request:URLRequest;
                var imageLoader:Loader = new Loader();

                if(GlobalVars.destinationInc < destinationAllObj.length)
                {
                    imageLoader.load((destinationAllObj[GlobalVars.destinationInc].ICON == "")? request = new URLRequest("images/school_32.png") : request = new URLRequest(destinationAllObj[GlobalVars.destinationInc].ICON));
                    imageLoader.name = String(destinationAllObj[GlobalVars.destinationInc].ICON);

                    someMarker = new Marker(result.point, new MarkerOptions({
                        icon: imageLoader,
                        tooltip: destinationAllObj[GlobalVars.destinationInc].SNAME+', '+destinationAllObj[GlobalVars.destinationInc].SLOC,
                        hasShadow: false
                    }));

                    someMarker.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void{
                        directionsSteps.removeAll();
                        var marker:Marker = event.target as Marker;
                        var markerContent:String = marker.getOptions().tooltip.toString();
                        var firstComma:Number = markerContent.indexOf(",");
                        textInput.text = markerContent.substr((firstComma+2),markerContent.length);
                        var tempInfoWinOpts:InfoWindowOptions = new InfoWindowOptions({
                            content: markerContent,
                            width: 450
                        });
                        marker.openInfoWindow(tempInfoWinOpts);

                        sendSomeLatLngToSv(event.latLng);

                        var lastIndexOfDashStr:String = marker.getOptions().icon.name;

                        GlobalVars.iconObj = lastIndexOfDashStr;
                        var tmpArr:Array = new Array;
                        var tmpStr:String = event.currentTarget.getOptions().tooltip;
                        tmpArr = tmpStr.split(',');
                        GlobalVars.panoAddr[0] = tmpArr[1];
                        GlobalVars.sName[0] = tmpArr[0];
                    });

                    googleMap.addOverlay(someMarker);
                    myMarkers.push(someMarker);
                    GlobalVars.destinationInc++;
                }

                for each(someMarker in myMarkers)
                {
                    var newLatLng:LatLng = someMarker.getLatLng();
                    bounds.extend(newLatLng);
                }

                if(destinationAllObj.length == GlobalVars.destinationInc)
                {
                    statusTxt.text = "Complete";
                    var tempNum:Number = googleMap.getBoundsZoomLevel(bounds);
                    googleMap.setCenter(bounds.getCenter(), (tempNum), MapType.HYBRID_MAP_TYPE);
                }

            });
            retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoderMarkersFailure);

            for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
            {
                statusTxt.text = "Processing data, please wait...";
                retrieveLatLngAddress.geocode(destinationAllObj[GlobalVars.destinationCounter].SLOC);
            }
        }

After an item has been clicked in the district datagrid, then wait 3 seconds and call the function once more. Functions similar to a refresh of a datagrid.

            public function selectedItemChanged(event:ListEvent):void
        {
            this.parentDocument.flexGoogleMap.directionsSteps.removeAll();
            tempId = event.currentTarget.selectedItem.district_id;
            this.parentDocument.passIdToRemoteGetSchoolsLocations(tempId);
            setTimeout(mTimeOut, 3000);
        }

        public function mTimeOut():void{
            this.parentDocument.passIdToRemoteGetSchoolsLocations(tempId)
        }

If status code of 500 is returned.

            public function geocoderMarkersFailure(event:GeocodingEvent):void
        {
            var result:Number = event.status;
            statusTxt.text = "Error: "+result+" processing address, re-processing, please wait 10-25 seconds...";
            GlobalVars.statusCode = result;
            if(GlobalVars.statusCode == 500)
            {
                setTimeout(statusFiveHundred, 10000);
                GlobalVars.statusCode = 0;
            }
        }

            public function statusFiveHundred():void{
            this.parentDocument.passAllDestinations();
        }

The this.parentDocument.passAllDestinations() calls makeMultipleMarkers, among other things.

Here's the URL to the app - still in testing phase: enter link description here

BTW, this app was made so that my boss does not have to drive to every school in Los Angeles. This way, he can click on a particular school district, followed by selecting a school next to a major thoroughfare (highway, three lane or two lane), determine if the school can place an ad near that particular, followed by his sales pitch to the school from there.

Another BTW, why does the .swf file from the bin-release folder not work, but the .swf from the bin-debug does?


Need Your Help

Scrolling Content With Fixed Navigation

html css

I'm stuck here. I can't quite figure out the correct syntax to get the layout of my site exactly right.

Reverse list of objects inside a list of object using linq

vb.net asp.net-mvc-3 linq linq-to-objects

I've a list of class type hotel which internally consists list of other class rooms. Now when i perform a descending sort i sort hotels in descending order but i also have to internally sort the ro...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.