I am in trouble to find a solution of my problem. I wrote an app which ask in a form an address and send a request to a mysql database through PHP. This is the extract of the APP code:
HttpPost httppost = new HttpPost("http://www.mywebsite.com/subfolder/selectall.php?PLAT=latitude_home&PLONG=longitude_home");
As you can see I am sending to the PHP page two parameters: Latitude and Longitude which are two DOUBLE variables.
The PHP code is the following:
$R_latitude = $_REQUEST['PLAT'];
$R_longitude = $_REQUEST['PLONG'];
$latitude = floatval($R_latitude);
$longitude = floatval($R_longitude);
$con = mysql_connect(server,database,password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$i=mysql_query("SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Lat`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Lat`*pi()/180)) * cos(((".$longitude."- `Lon`) * pi()/180))))*180/pi())*111.18957696) as distance FROM `Table` ORDER BY distance ASC LIMIT 10",$con);
It is supposed I get the results in order of distance from the point of interest, but what I get with this code is that the order is wrong, while if I use a fix value of latitude and longitude everything is fine:
// $latitude = floatval($R_latitude);
// $longitude = floatval($R_longitude);
$latitude = 45.4283585;
$longitude = 10.9669789;
What is wrong here ? IS someone able to help ? Thanks a lot and happy new year !