GetDistance Javascript没有返回任何内容,同时具有一些参数值(GetDistance Javascript not returning nothing whilst having

编程入门 行业动态 更新时间:2024-10-22 08:43:10
GetDistance Javascript没有返回任何内容,同时具有一些参数值(GetDistance Javascript not returning nothing whilst having some values for as parameters)

我试图从这个函数得到一个结果。 但是,没有任何内容返回到我的页面,只是“此示例调用执行计算的函数,并返回结果:”。 我需要这个函数从属性表中获取数据库中的每个邮政编码并找到距离。 此外,一个邮政编码总是设置相同所以我需要设置它,而另一个邮政编码将是属性表中的邮政编码。

<?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>

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);

Where are you using the x variable?

I would expect something like this:

<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);

更多推荐

本文发布于:2023-07-25 05:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   内容   Javascript   GetDistance   values

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!