2016-03-26 5 views
0

私はこの関数から結果を得ようとしています。しかし、何も私のページに返されていません、ちょうど "この例では計算を実行し、結果を返します:"私はプロパティテーブルからデータベースのすべての郵便番号を取得し、距離を見つけるためにこの関数が必要です。また、1つの郵便番号は常に同じになるように設定されているので、それを設定する必要があり、もう1つの郵便番号はプロパティテーブルの郵便番号になります。GetDistanceパラメータとしていくつかの値を持っている間にJavascriptは何も返さない

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

あなたがJavaScriptなどのPHPコードを実行しようとしている - それが仕事に行くのではないですが。 – georg

+0

@georgご回答ありがとうございます – JackDaniels

+0

どうすればこのコードをテストできますか? – JackDaniels

答えて

1

ここで、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); 
+0

あなたのコードを挿入しても何も表示されません。 – JackDaniels

関連する問題