本文介绍了GetDistance Javascript不返回任何内容,但具有作为参数的某些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从此函数获得结果.但是,什么也没有返回到我的页面上,只是此示例调用了执行计算并返回结果的函数:".我需要此函数来从属性表中获取数据库中的每个邮政编码并找到距离.另外,设置一个邮政编码始终是相同的,因此我需要进行设置,而另一个邮政编码将成为属性表中的邮政编码.
I am trying to get a result from this function. However, nothing is being returned onto my page, just "This example calls a function which performs a calculation, and returns the result:". I need this function to get every postcode in the database from the properties tables and find the distance. Also, one postcode is set always going to be the same so I need to set that and the other postcode is going to be a postcode from the properties table.
<?php
include ("../connect.php");
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>This example calls a function which performs a calculation, and returns the result:</p>
<p id="demo"></p>
<script type="text/javascript">
var x = getDistance(52.482799000000000, -2.000643000000000, 52.48463500000000, -1.980759000000000);
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$postLat = deg2rad($latitude2 - $latitude1);
$postLon = deg2rad($longitude2 - $longitude1);
$a = sin($postLat/2) * sin($postLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($postLon/2) * sin($postLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
//$distance_miles = $km * 0.621371; //distance in miles
return $d;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
推荐答案
您在哪里使用x变量?
我希望这样的事情:
<p>This example calls a function which performs a calculation, and returns the result:
<div id="result">
</div>
</p>
var x = getDistance(52.482799000000000, -2.000643000000000, 52.48463500000000, -1.980759000000000);
$('#result').text(x);
这篇关于GetDistance Javascript不返回任何内容,但具有作为参数的某些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!