-2

距離計算用のこの簡単なコードがあり、ここで見つけまし

ただし、サーバーにアップロードするとまったく機能しない理由がわかりません。

これはコードです:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<?php

    $distances = array();
    $distances[0] = array("id"=>"0","name"=>"Pittsburgh","long"=>"-79.9954","lat"=>"40.4409");
    $distances[1] = array("id"=>"1","name"=>"Las Vegas","long"=>"-94.1024","lat"=>"36.1749");
    $distances[2] = array("id"=>"2","name"=>"Beaumont","long"=>"-79.9954","lat"=>"30.0862");
    $distances[3] = array("id"=>"3","name"=>"South Bend","long"=>"-86.2517","lat"=>"41.673");
    $distances[4] = array("id"=>"4","name"=>"Hampton","long"=>"-76.3447","lat"=>"37.03");
    $distances[5] = array("id"=>"5","name"=>"Savannah","long"=>"-81.0946","lat"=>"32.0728");


    if(getenv("REQUEST_METHOD")=="POST")
    {

        $lon1 = $distances[$from]["long"];
        $lat1 = $distances[$from]["lat"];

        $lon2 = $distances[$to]["long"];
        $lat2 = $distances[$to]["lat"];

        $distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180);

        $summary = "Total distance between ".$distances[$from]["name"]." and ".$distances[$to]["name"]." is ".sprintf("%01.02d",$distance)." km";
        $summary.= "<br><br>( $lon1,$lat1 )  ($lon2,$lat2)";
    }

?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><form name="form1" method="post" action="">
      <table width="400" border="0" cellpadding="0" cellspacing="0" class="bodytext">
        <tr>
          <td width="166"><select name="from" class="bodytext">
<?php foreach ($distances as $value){?>
<option <?php if($from==$value["id"])print("selected");?> value="<?php print($value["id"]);?>"><?php print($value["name"]);?></option>
<?php }?>
 </select></td>
          <td width="117"><select name="to" class="bodytext">
<?php foreach ($distances as $value){?>
<option <?php if($to==$value["id"])print("selected");?> value="<?php print($value["id"]);?>"><?php print($value["name"]);?></option>
<?php }?>
 </select></td>
          <td width="117"><input name="Submit" type="submit" class="bodytext" value="Calculate"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3">
<?php   print($summary); ?></td>
          </tr>
      </table>
    </form></td>
  </tr>
</table>
</body></html>

私は何かを逃していますか?私は今コードを更新しました。最後のコードが間違っていました。申し訳ありません。

4

1 に答える 1