我想创建一个数组,其中包含每行的多个值(例如Latitude,Longitude)。
我在我的PHP代码中试过这个:
<?php
$latitudeFrom =$_POST['latitudeFrom'];
$longitudeFrom =$_POST['longitudeFrom'];
$radius=$_POST['radius'];
$conn=mysql_connect($hostname,$user,$pass);
$db=mysql_select_db('my_finditdatabase');
//$latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo,
$earthRadius = 6371000;
$ris=mysql_query("SELECT * FROM Parcheggio;")or die('died');
$riga=mysql_fetch_array($ris);
$i=0;
while($riga)
{
$latitudeTo=$riga['Latitudine'];
$longitudeTo=$riga['Longitudine'];
//print "lat:{$latitudeTo} lon:{$longitudeTo} ";
// convert from degrees to radians
$latFrom = deg2rad($latitudeFrom);
$lonFrom = deg2rad($longitudeFrom);
$latTo = deg2rad($latitudeTo);
$lonTo = deg2rad($longitudeTo);
//print "___lat:{$latTo}___lon:{$lonTo} ";
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
$dist= $angle * $earthRadius;
//print "====dist:{$dist} <br> ";
if($dist<=$radius){
//print "<br><br> Ci sono ";
$Citta=$riga['Citta'];
$Via=$riga['Via'];
$Provincia=$riga['Provincia'];
$NumCivico=$riga['NumCivico'];
//print "<br><br> Citta:{$Citta}--Via: {$Via}--Provincia:{$Provincia}---NumCivico:{$NumCivico} <br>";
$newdata=array("Citta" => $Citta, "Provincia" => $Provincia , "Via" => $Via , "NumCivico" => $NumCivico ,"Latitude" => $latitudeTo , "Longitude" => $longitudeTo);
array_push($md_array[$i],$newdata);
$i++;
}
$riga=mysql_fetch_array($ris);
}
print(json_encode($arr));
mysql_close();
?>
如果它进入IF BLOCK,它应该为具有theese值的te数组添加一行:
$newdata=array("Citta" => $Citta, "Provincia" => $Provincia , "Via" => $Via , "NumCivico" => $NumCivico ,"Latitude" => $latitudeTo , "Longitude" => $longitudeTo);
array_push($md_array[$i],$newdata);
我想说这个方法是否有效以及如何打印数组并从我的Java类中读取它来发出http请求。