Question

This is mycode:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(int x = firstVisibleItem; x < lastVisibleItem; x++){
    builder.include(temp.getPosition());
}

However this line throws an error (java.lang.IllegalStateException: no included points :

double north = builder.build().northeast.latitude;

This is because the above loop didn't run at all so no points were included in the builder.

How can I check if the builder has at least one point?

I tried builder.build()!=null which throws the above error and builder!=null which is always True.

try{}catch(IllegalStateException e){ } works. Is it stupid to ask a !=null way? Mico-management? Thanks

Was it helpful?

Solution

You can create a counter and use it to verify that you have at least one point.

int counter = 0;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(int x = firstVisibleItem; x < lastVisibleItem; x++){
    counter++;
    builder.include(temp.getPosition());
}
if (counter > 0) {
    //use a LatLngBounds.Builder to build the LatLngBounds object
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top