views:

12

answers:

0

Hi guys,

I need to call an address list to add markers on google map for each address. This operation should be performed as follows:

1-address list will be loaded into a list

2-each address will be searched to find lat and lng values

3-then a marker will be placed

List might include an animation icon. All icons will be running in the beginning.After the current marker is placed, its animation icon will be stopped. This will go one by one. I have just written the explanation so you will have a clear picture what I am trying to do and give me some suggestion.

This link tells what I need but it just shows examples working with some other pages. http://docs.jquery.com/How_jQuery_Works#Callback_and_Functions

Each marker should wait for the previous one or suggest me sth else please.

I have found sth like this but I could not figure it out how to adjust it into my code.

THIS IS THE SAMPLE

    function translate(i) {
          google.language.translate(testua, languages[i], languages[i+1], function(result) {
            if (result.translation) {
              text = result.translation;
              f.textarea1.value = text;
              if (i < translationNumber) { translate(i++); }
            }
          }
    }

//MY CODE: in loadAddresses function or in another function, how can I make them wait for each other?

    function loadAddresses (){

        var dummyAddresses = [

            {name: "Lidcombe", address: "Lidcombe Station NSW"},
            {name: "Parramatta", address: "Parramatta Station NSW"},
            {name: "Berala", address: "Berala Station NSW"},
            {name: "Banksia", address: "Banksia Station NSW"},
            {name: "Burwood", address: "Burwood Station NSW"} ];

        secondaryAddressArray = dummyAddresses;

        $(secondaryAddressArray).each(function(ind){

            var addressName = secondaryAddressArray[ind].name;
            var address = secondaryAddressArray[ind].address;

            //alert(addressName +"--"+ address);
            geoEncodeSecondary(addressName, address);


        });
    }


    //add point button calls geoEncodeSecondary function.
    //This function first checks if given address is valid.
    //If it is, then further actions are performed in 'if case'.
    function geoEncodeSecondary(loc_name, address) {        

        geo.getLocations(address, function (result){                        

            if (result.Status.code == G_GEO_SUCCESS) {      

                geocode = result.Placemark[0].Point.coordinates;                            
                savePointSecondary(geocode, loc_name);  

            } else {    

                var reason="Code "+result.Status.code;                          
                if (reasons[result.Status.code]) {                              
                    reason = reasons[result.Status.code]                            
                }                           

                $("#add-point .error2").html(reason).fadeIn();                          
                geocode = false;    

            }                   
        }); 

    }   

Any suggestion is appreciated. Thanks in advance.. Regards... Ozlem.