iterating multidim array of locations

Go To StackoverFlow.com

0

I'm migrating gmaps from Java V2 to Java V3 and had an issue when trying to place multiple locations on a map at the same time. The process bombs out. This was due to a syntactical error (thanks Chang for pointing it out). The following has been edited (from original post) and works as expected.

External script file:

//<![CDATA[    
function initialize() {
var myOptions = {
center: new google.maps.LatLng(41, -81.64),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

setMarkers(map, storeloc);
}

/*
* create a multidim array of locations,
* array elements title,lat,lng,zIndex.
*/
var storeloc = [
    ['7515 Auburn Road Painesville', 41.66, -81.24, 4],
    ['8775 Darrow Road Twinsburg', 41.305634, -81.440208, 3],
    ['2496 E Aurora Road Twinsburg', 41.311218, -81.459404, 2]
    ];

/*
* Define setMarkers function with map and locations parameters
* storeloc multidim array assigned to locations
*/
function setMarkers(map, locations){

var i;
for (i = 0; i < locations.length; i++) {
      var store = locations[i];
      var myLatLng = new google.maps.LatLng(store[1], store[2]);
      var marker = new google.maps.Marker({
         position: myLatLng,
         map: map
      });
    }
  }

//edit
google.maps.event.addDomListener(window,'load',initialize);
//]]>

Then in HTML called initialize() function with: body onload="initialize()"

Before adding the addDomListener to the end of the script file, I was getting an error saying initialize not valid. RWhite35

2012-04-05 17:47
by rwhite35
Are you saying that the the questions has been answered? If so you should yourself post an answer and accept it. This way others will know that it has been resolved and won't bother reading - James Montagne 2012-04-05 20:57
Will do, have to wait 8 hours. Newbie and all that. Thanks - rwhite35 2012-04-05 22:40


0

The above edited post is the answer to this issues. I added the following DOM listener line to the end of the script in addition to calling the initialize() function inside the HTML body tag with an onload event handler.

google.maps.event.addDomListener(window,'load',initialize);
2012-04-06 01:55
by rwhite35
Ads