Nubaslon
Nubaslon

Reputation: 751

How to get count of markers at visible region on map

Please help!!! i have read - How to get all visible markers on current zoom level , but i have over than 2000 markers on map, and my app works very slowly.

Is there another solution ???

code -

public boolean isVisibleArea(final Marker marker) {
   final LatLngBounds.Builder bld = new LatLngBounds.Builder();
   final VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
   bld.include(visibleRegion.farLeft)
      .include(visibleRegion.farRight)
      .include(visibleRegion.nearLeft)
      .include(visibleRegion.nearRight);
   return bld.build().contains(marker.getPosition());

}

Upvotes: 4

Views: 2556

Answers (1)

muetzenflo
muetzenflo

Reputation: 5690

I am not sure if it is really faster, but this code is definitely cleaner:

public boolean isVisibleOnMap(LatLng latLng) {
    VisibleRegion vr = mMap.getProjection().getVisibleRegion();
    return vr.latLngBounds.contains(latLng);
}

Upvotes: 3

Related Questions