UP!
This issue is still requiring attention, since in dynamic pages or even in
common-use CMSes like Wordpress you can't always know how many maps you're
going to display, and how to set unique DIV IDs and Object names
accordingly.
The following code is meant to use class selectors (or any other HTML
element array) but it DOES NOT WORK, neither for the last map:
// vars generated by PHP, corresponding to DIV IDs, later processed with
eval
var show_google_maps = true;
var my1containerDivId = {'Asy Place, London, E1 1JG'};
var my1containerDivId = {'51 abs Ave, UK'};
if (typeof google_maps != "undefined") {
var geocoder=new Array();
var map=new Array();
var mapContainer;
var mapId=new Array();
var marker=new Array();
var address=new Array();
var myOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
mapContainer = $('.wpec_google_maps');
for (i=0; i<mapContainer.length; i++){
mapId[i] = mapContainer[i].id;
eval('address[i] = '+mapId[i]+'.address;');
map[i] = new google.maps.Map(document.getElementById(mapId[i]),
myOptions);
geocoder[i] = new google.maps.Geocoder();
alert(i);
geocoder[i].geocode( { 'address': address[i] },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(i-1);
map[i-1].setCenter(results[0].geometry.location);
alert(i-1);
marker[i-1] = new google.maps.Marker({
map: map[i-1],
position: results[0].geometry.location
});
alert(i-1);
}
});
}
}
By the way, it seems to be consistent until the last part, but when I was
simply using map[i].setCenter it throwed out the error "map[i] is
undefined". Then I found this thread, I started firing alert(i) everywhere
and it seems that the shifting [i] is related less to Geocoder being
asynchronous than to the object arrays manipulation.
1- Could the Map's and Geocoder's methods be attached to their array
instances?
2- From what I see, everytime this tries to occur, it leads to an index [i]
increase... is it true?
3- So I've tried to revert it back with map*[i-1]* and *no more JS errors
are reported*, the *response png images are ok* when looking into the
request debugger (Firebug Net Console), but the canvas is still blank!!
Obviously the index becomes meaningless, should I better process the array
instance with 'slice', or 'call', or 'apply' or maybe 'prototype' ?
--
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.