【发布时间】:2015-02-17 10:48:42
【问题描述】:
我在使用 google Maps API 中的 updateMap 函数时遇到问题...特别是使用多个“else if”语句来查询数据。我的代码如下。第一个“if”有效,第一个“else if”有效,最后一个“else”更新我的地图,第二个“else if”不会更新我的地图。用户通过下拉菜单传递“Type”和“Visibilit2”的值。
有什么建议可以解决这个问题吗?通过将下拉菜单设置为空白(这是最后一个 else 所考虑的),地图需要根据来自任一、两者或两者的用户值进行更新。理想情况下,我想将其扩展为包括三个或四个额外的查询选项。数据存储在 Fusion Table 中。
google.maps.event.addDomListener(document.getElementById('Type'), 'change', function(){updateMap(layer, tableID, locationColumn);});
google.maps.event.addDomListener(document.getElementById('Visibilit2'), 'change', function(){updateMap(layer, tableID, locationColumn);});
function updateMap(layer, tableID, locationColumn){
var Type = document.getElementById('Type').value;
var Visibilit2 = document.getElementById('Visibilit2').value
if (Type, Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "' AND Visibilit2 = '" + Visibilit2 + "'"
}
});
} else if (Type){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "'"
}
});
} else if (Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Visibilit2 = '" + Visibilit2 + "'"
}
});
}
else {
layer.setOptions({
query: {
select: locationColumn,
from: tableID
}
});
}
}
【问题讨论】:
标签: javascript google-maps google-maps-api-3 google-fusion-tables