Skip to content

Instantly share code, notes, and snippets.

@JohnMars
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save JohnMars/a60b735d539c3a2bcc89 to your computer and use it in GitHub Desktop.

Select an option

Save JohnMars/a60b735d539c3a2bcc89 to your computer and use it in GitHub Desktop.
Dynamically adding cluster items to avoid lagging while moving Google maps camera
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
new DynamicallyAddMarkerTask().execute(bounds);
}
});
private class DynamicClusteringTask extends AsyncTask<LatLngBounds, Void, Void> {
@Override
protected Void doInBackground(LatLngBounds... bounds) {
clusterManager.clearItems();
for (Filial currentPoint : filialList) {
if (bounds[0].contains(currentPoint.getPosition())) {
clusterManager.addItem(currentPoint);
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
clusterManager.cluster();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment