This is a bug in your code, not a problem in the Maps API. Your variable 'i'
doesn't contain what you expect, because that's how JavaScript works. Read
up on closures to better understand the problem and how to fix it.

I assume you are using jQuery, is that right? Then interestingly enough,
this all would have worked if you'd used jQuery's .each() method instead of
writing your own 'for' loop - because .each() takes a callback function, and
that creates the closure you need.

Here's a cleaned-up, untested version of your code that uses techniques that
will work:

if( typeof google_maps != "undefined" ) {
    initMaps();
}

function initMaps() {
    $('.wpec_google_maps').each( function( i, container ) {
        var options = {
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map( container, options );
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': address[i] }, function(results,
status) {
            var location = results[0].geometry.location;
            if( status == google.maps.GeocoderStatus.OK ) {
                map.setCenter( location );
                var marker = new google.maps.Marker({
                    map: map,
                    position: location
                });
            }
        });
    });
}

-Mike

-- 
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 [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-js-api-v3?hl=en.

Reply via email to