我只是想为Google Places api获得5个结果,这将带出它可以找到的所有结果,但是我只想要前5个,看来我什至无法对此做出任何更改。我尝试先在循环之前添加一个计数器,然后再将其递增1,直到达到5,但我认为它无法正常工作。
有任何想法吗?
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
for (PlaceLikelihood placeLikelihood : likelyPlaces) //I need to limit this to only 5 results {
...
最佳答案
使用计数器并在计数器达到5时休息。
counter=0;
for (PlaceLikelihood placeLikelihood : likelyPlaces){
if(counter==5){
break;
}
counter+=1;
//do your stuff here with the 5 locations
}