我试图查看输入的纬度和经度是否与两种类型的多边形之一相对应,一种具有“Live”键,另一种具有“Soon”键,但是我似乎无法写入 if 语句。
因此,如果纬度 + 经度点位于实时多边形类型中,则结果应该是:位置已找到并且处于实时状态。如果纬度 + 经度点属于多边形类型,很快结果应该是“位置已找到并且即将出现”。如果纬度 + 经度不位于多边形中,结果应该是“未找到位置”。
我的 if 语句做错了什么?
initGeocompleteControl(map, function (result) {
map.data.forEach(function (f) {
if (f.getProperty("key") == "live") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$( "#result" ).empty();
$("#result").html('Location is found and is live');
} else if (f.getProperty("key") == "soon") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$( "#result" ).empty();
$("#result").html('Location is found and is coming soon');
} else {
$( "#result" ).empty();
$("#result").html('Location is not found');
}
//w11 2ed
}
// w10 5nr
}
});
});
最佳答案
将 else if 条件放在 ie 之外。在 if(f.getProperty("key"...
initGeocompleteControl(map, function (result) {
map.data.forEach(function (f) {
if (f.getProperty("key") == "live") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$( "#result" ).empty();
$("#result").html('Location is found and is live');
}
//the else if moved from here
}
else if
(f.getProperty("key") == "soon") {
var bounds = new google.maps.LatLngBounds();
calcBounds(f.getGeometry(), bounds);
if (bounds.contains(result.geometry.location)) {
$( "#result" ).empty();
$("#result").html('Location is found and is coming soon');
}
//else condition moved from here
} //and else condition after the else if condtion
else {
$( "#result" ).empty();
$("#result").html('Location is not found');
}
//w11 2ed
// w10 5nr
});
});
关于javascript - 如果声明问题不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35011080/