我今天一直盯着屏幕看,似乎无法理解为什么这个if语句似乎不起作用。 Google Distance API输出一个值和km,即17.8 km,eDistance输出50。
if(distanceGoogle("https://maps.googleapis.com/maps/api/distancematrix/json?key=AIzaSyCd8iWEixVcMXRv3qQretshh33duoJ_YT8&address=http://example.co.uk&origins=$eventPostcode&destinations=$Postalcode&mode=$ModeSelected&language=en-EN&sensor=false") <= $eDistance){
?>
<script type="text/javascript">
$(window).load(function(){
$('#eventModal').modal('show');
});
</script>
<?php
$ui->setAttribute('eventnotify', $eventPostcode);
} else {
//Further than distance criteria
}
当Google计算的距离超过eDistance(50)时,这应该只执行程序(加载模式),但事实并非如此。某处可能是一个非常愚蠢的错误!
答案 0 :(得分:0)
据我所知,<=
应为>=
,因此,如果Google距离小于或等于50且不大于或等于50,则代码会运行。因此,您的代码应为:
if(distanceGoogle("https://maps.googleapis.com/maps/api/distancematrix/json?key=AIzaSyCd8iWEixVcMXRv3qQretshh33duoJ_YT8&address=http://example.co.uk&origins=$eventPostcode&destinations=$Postalcode&mode=$ModeSelected&language=en-EN&sensor=false") >= $eDistance){
?>
<script type="text/javascript">
$(window).load(function(){
$('#eventModal').modal('show');
});
</script>
<?php
$ui->setAttribute('eventnotify', $eventPostcode);
} else {
//Further than distance criteria
}