近くの場所のため、このPOSTメソッドを使用し
メートルであなたのSEARCH TYPEと半径を設定します。
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" + "?location=" + location.getLatitude() + "," + location.getLongitude() + "&radius=" + RADIUS_IN_METERS + "&type=" + SEARCH_TYPE + "&key=" + API_KEY;
Log.d(TAG, url);
Map<String, String> params = new HashMap<>();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
locationList = new ArrayList<>();
JSONArray results = response.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject geometry = results.getJSONObject(i).getJSONObject("geometry");
String name = results.getJSONObject(i).getString("name");
String address = results.getJSONObject(i).getString("vicinity");
String place_id = results.getJSONObject(i).getString("place_id");
if (geometry != null) {
JSONObject location = geometry.getJSONObject("location");
if (location != null) {
double latitude = location.getDouble("lat");
double longitude = location.getDouble("lng");
if (latitude != 0.0 && longitude != 0.0) {
Location markerLocation = new Location(SEARCH_TYPE);
markerLocation.setLatitude(latitude);
markerLocation.setLongitude(longitude);
Bundle bundle = new Bundle();
bundle.putString("NAME", name);
bundle.putString("ADDRESS", address);
bundle.putString("PLACE_ID", place_id);
bundle.putString("TYPE", SEARCH_TYPE);
markerLocation.setExtras(bundle);
locationList.add(markerLocation);
Log.d(TAG, latitude + " " + longitude);
}
}
}
}
if (locationList.size() != 0) {
addMarkers(SEARCH_TYPE);
}
//Log.d(TAG,results.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(jsonObjectRequest);