Javascript 访问标记图标的图像数组元素

Javascript 访问标记图标的图像数组元素,javascript,arrays,google-maps,google-maps-api-3,Javascript,Arrays,Google Maps,Google Maps Api 3,我想为数组中的每个标记使用不同的图标。我只是在我的位置数组的末尾添加了图标路径(作为字符串)。 我不确定是否在循环的“标记”中正确访问了图标 当我运行时,控制台中出现以下错误: Uncaught InvalidValueError: setIcon: not a string; and no url property; and no path property 我认为这告诉我路径不正确/不在那里,但这是正确的,因此我认为它没有正确访问阵列。 我应该怎么做?或者图标本身应该在一个单独的数组中吗

我想为数组中的每个标记使用不同的图标。我只是在我的位置数组的末尾添加了图标路径(作为字符串)。
我不确定是否在循环的“标记”中正确访问了图标

当我运行时,控制台中出现以下错误:

Uncaught InvalidValueError: setIcon: not a string; and no url property; and no path property
我认为这告诉我路径不正确/不在那里,但这是正确的,因此我认为它没有正确访问阵列。
我应该怎么做?或者图标本身应该在一个单独的数组中吗

编辑:如果图标位于单独的数组中,则可以正确加载图标,但是我想知道是否可以使用一个多维数组,而不是多维数组和另一个标准数组

function initialize() {

var locations = [
     ['Title A', 3.180967,101.715546, 1, '/images/icons/letter_a.png'],
     ['Title B', 3.200848,101.616669, 2,'/images/icons/letter_b.png'],
     ['Title C', 3.147372,101.597443, 3,'/images/icons/letter_c.png'],
     ['Title D', 3.19125,101.710052, 4, '/images/icons/letter_d.png']
];



  var myLatlng = new google.maps.LatLng(3.182362,101.044922);

  var mapOptions = {
    zoom: 4,
    center: myLatlng
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var infowindow = new google.maps.InfoWindow;
  var marker, i;

  for (i = 0; i < locations.length; i++){
    marker = new google.maps.Marker({
      position: new google.maps.LatLng(locations[i][1], locations[i][2]),
      map: map,
        icon: locations[i][3]
    });
    google.maps.event.addListener(marker, 'click', (function(marker, i) {
         return function() {
             infowindow.setContent(locations[i][0]);
             infowindow.open(map, marker);
         }
    })(marker, i));

  }

}

google.maps.event.addDomListener(window, 'load', initialize);
函数初始化(){
变量位置=[
[Title A',3.180967101.715546,1',/images/icons/letter_A.png'],
[Title B',3.200848101.616669,2',/images/icons/letter_B.png'],
[Title C',3.147372101.597443,3',/images/icons/letter_C.png'],
['Title D',3.19125101.710052,4',/images/icons/letter_D.png']
];
var mylatng=new google.maps.LatLng(3.182362101.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var infowindow=new google.maps.infowindow;
var标记,i;
对于(i=0;i
您的数组位置有误
图标:位置[i][3]
是一个数值
图标:位置[i][4]
是图标URL的参考,更改这一行,您将在那里:)

啊,是的,我似乎算错了!