 |
|
Code (Android-Java)
keyword = (EditText)findViewById(R.id.keyword);
searchPlace = (Button)findViewById(R.id.searchPlace);
searchPlace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" +
keyword.getText().toString() + "&key=" + API_KEY;
Log.d("URL Request", url);
new RequestTask().execute(new String[]{url});
}
});
public class RequestTask extends AsyncTask<String, Void, JSONObject> {
@Override
protected JSONObject doInBackground(String... url) {
String urlQuery = url[0];
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
JSONObject jsonRes = null;
HttpPost post = new HttpPost(url[0]);
try {
StringEntity se = new StringEntity(urlQuery.toString(), HTTP.UTF_8);
Log.d("URL", url[0]);
Log.i("SEND QUERY", urlQuery.toString());
post.addHeader("content-type", "application/json;charset=UTF-8;");
post.setEntity(se);
HttpResponse response;
response = client.execute(post);
resFromServer = EntityUtils.toString(response.getEntity());
Log.i("JSON Response", resFromServer);
} catch (Exception e) {
e.printStackTrace();
}
return jsonRes;
}
}
Tag : Mobile, Android, Mobile
|
|
 |
 |
 |
 |
Date :
2015-07-17 14:51:58 |
By :
funrun |
View :
1188 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |