I have an array named "data"  which is filled with some address string
like["New York","Nanjing","Boston"...]. And I want to geocode the
array to add markers in a google map. But when i recall geocode() in a
loop . The callback function excute only once when the loop is ended.
Can you help me~~
A function is defined as follows
function getCoordinates(address) {
        var geocoder = new google.maps.Geocoder();
        var geocoderRequest = {
                address: address
        };
        geocoder.geocode(geocoderRequest, function(results, status) {
                if(status == 'OK') {
                        if(!marker) {
                                marker = new google.maps.Marker({
                                        map: map
                                });
                        }
                        var location = results[0].geometry.location;
                        marker.setPosition(location);
                        markers.push(marker);           //markers is an Array 
that defined
global for remove or delete the marker later
                        }
        });
}

and when I recall this function in a loop, for example:
for(var i in data) {
                        getCoordinates(data[i]);   //data is a string array 
filled with
address
                };

callback function will not excute until the for loop is ended.
Why????? How can i fix this?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to