So, I'm writing an Android app, and part of it is supposed to use GPS to get longitude / latitude. And these values should be published on the PHP server, in which I also work. The function I post is as follows:
public void doAll() {
Double locLat, locLon;
try {
locLat = locManager.getLastKnownLocation(locProvider).getLatitude();
locLon = locManager.getLastKnownLocation(locProvider).getLongitude();
} catch (NullPointerException e) {
locLat = -1.0;
locLon = -1.0;
}
try {
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://fatalatour.com/database.php?function=get_all&latitude="+Double.toString(locLat)+"&longitude="+Double.toString(locLon));
ResponseHandler <String> responseHandler = new BasicResponseHandler();
String response = client.execute(request, responseHandler);
Log.i("HOMI_RESPONSE", response.toString());
}
There is other code with this, but I believe that this is all that actually affects the publication of locLat and locLon.
For the end of the server, I have:
function get_all() {
$lat = trim($_GET['latitude']);
$lon = trim($_GET['longitude']);
$f = fopen('debug.log', 'a');
fprintf($f, 'get_all: '.print_r($_REQUEST, true)."\n");
$result = mysql_query("SELECT * FROM homi_table");
$num = 0;
while ($row = mysql_fetch_assoc($result)) {
$d = distance($row['latitude'], $row['longitude'], $lat, $lon, "K");
if ($d < 100) {
$num += 1;
echo "fatality:".$row['slug']."~".strtoupper($row['name']).", Age ".$row['age']."\n".$row['date']."\nhttp://projects.latimes.com/homicide/post/".$row['slug']."~".$row['latitude']."~".$row['longitude'];
if ($num == 100) {
break;
}
}
};
echo $num;
fprintf($f, "get_all: returning: ".$num."\n");
}
The problem now is handling $ lat and $ lon. When I hard-code the static number for each of them in PHP, the application works, but when I leave it variable (as it should be), it fails. Any help would be greatly appreciated!
source
share