2012-04-28 170 views
-1

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

回答

0

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