Last active
August 29, 2015 14:03
-
-
Save JohnMars/a60b735d539c3a2bcc89 to your computer and use it in GitHub Desktop.
Dynamically adding cluster items to avoid lagging while moving Google maps camera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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