将LatLong发送到服务器

时间:2012-04-28 08:23:00

标签: android ip-address

我创建了一个Lat-Long应用程序,需要将收到的Lat-Long发送到服务器并将其存储在我的数据库中。请建议我如何将lat-long发送到服务器。

1 个答案:

答案 0 :(得分:0)

如果你使用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();
        }