我正在将 gmap 从 Java V2 迁移到 Java V3,并且在尝试同时在地图上放置多个位置时遇到问题。过程爆炸了。这是由于语法错误(感谢 Chang 指出)。以下内容已被编辑(来自原始帖子)并按预期工作。
外部脚本文件:
//<![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);
//]]>
然后在 HTML 中调用 initialize() 函数:body onload="initialize()"
在将 addDomListener 添加到脚本文件的末尾之前,我收到一条错误消息,提示初始化无效。RWhite35