Check LatLngBounds.Builder if null

孤者浪人 提交于 2019-12-20 01:45:01

问题


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


回答1:


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
}


来源:https://stackoverflow.com/questions/21667506/check-latlngbounds-builder-if-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!