Reputation: 2697
I'm unable to get JSON
Response when using Android Volley. No Error also No Succesfull response see (Log.d("logr=",_response);
). I use StringRequest to get JSON text from Google Map API Android V2. Here're the code
private String urla = "https://maps.googleapis.com/maps/api/place/search/json?location=";
private String urlb = "&types=hotel&radius=500&sensor=false&key=YOUR_KEY";
@Override //::LocationListener (Interface)
public void onLocationChanged(Location location) {
//Log.d(TAG, "Firing onLocationChanged..............................................");
mCurrentLocation = location;
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()), 13);
googleMap.animateCamera(cameraUpdate);
double x = location.getLatitude();
double y = location.getLongitude();
String request = urla+x+","+y+urlb;
Log.d("log1=",request);
StringRequest stringRequest = new StringRequest(Request.Method.GET, request,
new Response.Listener<String>() {
@Override
public void onResponse(String _response) {
Log.d("logr=",_response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Error handling
Log.d("log2=", error.toString());
Log.e("log3=", error.toString());
}
});
Toast.makeText(activity, "Update location user ==>" + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude(), Toast.LENGTH_SHORT).show();
Log.d(TAG, "Current Location :" + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude());
}
Any Solution to this problem ?
Upvotes: 0
Views: 7058
Reputation: 2845
Try this:
requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
final StringRequest stringRequest = new StringRequest(Request.Method.POST, urlString, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
strr = response;
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.hide();
Log.e("Volley", "ERROR");
}
});
requestQueue.add(stringRequest);
Upvotes: 0
Reputation: 2428
Where do you actually excecute the request? You have to add()
it to Volley's RequestQueue
, otherwise the request does not get send at all.
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url = urla + x + "," + y + urlb;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String _response) {
Log.d("logr=",_response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Error handling
Log.d("log2=", error.toString());
Log.e("log3=", error.toString());
}
});
//excecute your request
queue.add(stringRequest);
See more here: Learn volley
Upvotes: 7