我有一个如下数据数组,可以通过按钮点击::
显示在Google地图上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”。
答案 0 :(得分:0)
那你的问题在哪里?代码看起来很好,只是在if之后省略分号(但这应该不是问题:
if (locations[i][2] == "small_red") {...}; // <-- remove the semicolon here
你还需要在某处调用你的函数:
selectIcon(locations);