-1
我創建了一個Lat-Long應用程序,需要將接收到的Lat-Long發送到服務器並將其存儲在我的數據庫中。請告訴我如何將lat-long發送給服務器。發送LatLong到服務器
我創建了一個Lat-Long應用程序,需要將接收到的Lat-Long發送到服務器並將其存儲在我的數據庫中。請告訴我如何將lat-long發送給服務器。發送LatLong到服務器
如果你正在使用MySQL,你可以使用接收lat和長爲參數,並將其解析到查詢PHP腳本..
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("lat", lat));
nameValuePairs.add(new BasicNameValuePair("lng", lng));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://yourserver.com/script.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch (Exception e) {
// TODO: handle exception
Log.e("log_tag", e.toString());
return false;
//Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}