Skip to content

Instantly share code, notes, and snippets.

@laabroo
Created June 16, 2012 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laabroo/2940184 to your computer and use it in GitHub Desktop.
Save laabroo/2940184 to your computer and use it in GitHub Desktop.
GetData From Server
public String loadData(double lat, double lon, double rad) {
httpGet = new HttpGet("http://laabroo.cu.cc/lokasi.php?lat=" + lat
+ "&lon=" + lon + "&rad=" + rad);
StringBuilder builder = new StringBuilder();
httpClient = new DefaultHttpClient();
try {
response = httpClient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statuscode = statusLine.getStatusCode();
if (statuscode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
Log.i("Data : ", line);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}
@laabroo
Copy link
Author

laabroo commented Jun 16, 2012

Ini adalah cara bagaimana mengambil data dari server dengan mengirimkan parameter Latitude, Longitude, Radius. Dan di kembalikan lagi menjadi sebuah object String.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment