我在应用程序中实现了google places api。但它只返回了20个结果。 检查发布的其他答案,从那里我开始知道我们需要为那个实现分页。 请提供一些解决方案。
我在这里附上代码
public ArrayList<Place> findPlaces(double latitude, double longitude,
String placeSpacification) {
ArrayList<Place> arrayList;
String urlString = makeUrl(latitude, longitude, placeSpacification);
System.out.println("url------"+urlString);
try {
String json = getJSON(urlString);
System.out.println(json);
JSONObject object = new JSONObject(json);
JSONArray array = object.getJSONArray("results");
arrayList = new ArrayList<Place>();
for (int i = 0; i < array.length(); i++) {
try {
Place place = Place
.jsonToPontoReferencia((JSONObject) array.get(i));
Log.v("Places Services ", "" + place);
arrayList.add(place);
} catch (Exception e) {
}
}
return arrayList;
} catch (JSONException ex) {
}
return null;
}
private String makeUrl(double latitude, double longitude, String place) {
StringBuilder urlString = new StringBuilder(
"https://maps.googleapis.com/maps/api/place/search/json?");
if (place.equals("")) {
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
//urlString.append("&radius=2000");
urlString.append("&types="+place);
urlString.append("&sensor=false&key=" + API_KEY);
} else {
//urlString.append("rankby=2000&location=");
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
urlString.append("&radius=2000");
urlString.append("&types=" + place);
urlString.append("&sensor=false&key=" + API_KEY);
}
return urlString.toString();
}
谢谢,