【发布时间】:2015-12-31 09:19:01
【问题描述】:
我在使用 Android Volley 时无法获得 JSON 响应。没有错误也没有成功的响应,请参阅 (Log.d("logr=",_response);)。我使用 StringRequest 从 Google Map API Android V2 获取 JSON 文本。这是代码
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());
}
这个问题有什么解决办法吗?
【问题讨论】:
-
为什么在谷歌地图上使用 volley??
-
@VivekMishra 我也在学习 volley 以避免写太多代码...
标签: android json connection android-volley