javascript - 如果声明问题不起作用

标签 javascript jquery html

我试图查看输入的纬度和经度是否与两种类型的多边形之一相对应,一种具有“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/

相关文章:

javascript - 使用选项值显示 block 和不显示

javascript - 重定向到其他页面英特尔 XDK

javascript - 忽略负鼠断路器中的 HTTP 404 错误

html - 如何使用 css 卡住 html 表中最右边的列?

javascript - 子组件使用 onChange(),更新父组件

javascript - Leaflet 和 jQuery mobile 不会合作

javascript - Chrome 65 阻止跨源 <a download>。强制下载的客户端解决方法?

javascript - js : how to NOT display adsense on cordova?

javascript - jQuery 无法在 Bootstrap 模式下工作

javascript - window.onload 和 document.ready : execution order in case specified multiple times