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
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);