私はAndroidアプリケーションを作成しています。その一部はGPSを使用して経度/緯度を取得することになっています。そしてそれらの値は、私も実行しているPHPサーバにポストされているはずです。次のように私は投稿を持っている機能は次のとおりです。AndroidからPHPサーバーへの情報の投稿
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();
//we put all the parameters in the URL itself
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();
//List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//nameValuePairs.add(new BasicNameValuePair("latitude", Double.toString(locLat)));
//nameValuePairs.add(new BasicNameValuePair("longitude", Double.toString(locLon)));
//request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
String response = client.execute(request, responseHandler);
Log.i("HOMI_RESPONSE", response.toString());
}
ありそのwithing他のコードですが、私はそれが実際にlocLatとlocLonの掲載に影響するすべてであると信じています。私は、サーバー側の場合
:
function get_all() {
$lat = trim($_GET['latitude']);
$lon = trim($_GET['longitude']);
// DEBUG
$f = fopen('debug.log', 'a');
fprintf($f, 'get_all: '.print_r($_REQUEST, true)."\n");
$result = mysql_query("SELECT * FROM homi_table");
$num = 0; //# of homicides
while ($row = mysql_fetch_assoc($result)) {
$d = distance($row['latitude'], $row['longitude'], $lat, $lon, "K");
if ($d < 100) { //number to change for distance filter
$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'];
// GH: limiting the number of results to 100
if ($num == 100) {
break;
}
}
};
echo $num;
fprintf($f, "get_all: returning: ".$num."\n");
}
今の問題は、$緯度と経度$の扱いのようです。 PHPのそれらのそれぞれの静的な数値をハードコードすると、アプリケーションは動作しますが、変数を残すと(失敗するはずです)失敗します。どんな助けでも大歓迎です!
アンドロイドコードからPOSTにアクセスするためにPHP内でGETを使用するはずがありませんか?これは素朴な質問であればごめんなさい。 – bezdomnyi
いいえ、いいえ、GETを使用できます。 AndroidアプリケーションではHttpGetを使用し、HttpPostは使用しないでください。 –
おはよう、ありがとう!私はその部分をJavaで修正した。これは意図したとおりに動作しています:) – bezdomnyi