-1

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

4

1 回答 1

0

如果您使用的是 MySQL,您可以使用接收 lat 和 long 作为参数并将它们解析为查询的 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();
        }
于 2012-04-28T08:32:27.783 回答