0

我有一个如下的数据数组,可以通过点击按钮在谷歌地图上显示:

var locations = [
[50.6343356475971,-9.53181026267496,"small_red","AGH","AGH1","GAS25"],
[40.2185001907869,0.928586419184371,"meassle_grey","BES1","BES","GAS23"],
[52.1400374749101,-7.50501915638024,"small_blue","DUB1","DUB","GAS24"],

为了定义每个类的图标,我尝试了以下操作但没有成功:

function selectIcon(locations) {
  for (var i = 0; i < locations.length; i++) {      //Loop trough List of Data
  if (locations[i][2] ==  "small_red") {
    iconIMG = new google.maps.MarkerImage("Link to the iconAAA.png");
  if (locations[i][2] ==  "small_blue") {
    iconIMG = new google.maps.MarkerImage("Link to the iconBBB.png");
  };

现在的问题是,对于所有 3 个位置,始终为所有标记显示“iconBBB.png”。

4

1 回答 1

0

那么你的问题在哪里?代码看起来不错,只是在 if 之后省略分号(但这不应该是问题:

if (locations[i][2] ==  "small_red") {...};  // <-- remove the semicolon here

您还需要在某处调用您的函数:

selectIcon(locations);
于 2013-02-01T14:38:24.017 回答