【发布时间】:2012-05-08 20:44:23
【问题描述】:
我创建了一个 Lat-Long 应用程序,它需要将接收到的 Lat-Long 发送到服务器并将其存储在我的数据库中。请建议我如何将经纬度发送到服务器。
【问题讨论】:
标签: android ip-address
我创建了一个 Lat-Long 应用程序,它需要将接收到的 Lat-Long 发送到服务器并将其存储在我的数据库中。请建议我如何将经纬度发送到服务器。
【问题讨论】:
标签: android ip-address
如果你使用 MySQL,你可以使用 php 脚本接收 lat 和 long 作为参数并将它们解析为查询..
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();
}
【讨论】: