@Override public void onMapReady(final GoogleMap googleMap) { this.googleMap = googleMap; googleMap.setMyLocationEnabled(true); if (callback != null) { callback.onMapReady(googleMap); } if (cameraChangeListener != null) { googleMap.setOnCameraChangeListener(cameraChangeListener); } googleMap.setOnMarkerDragListener( new GoogleMap.OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker arg0) {} @SuppressWarnings("unchecked") @Override public void onMarkerDragEnd(Marker arg0) { googleMap.animateCamera(CameraUpdateFactory.newLatLng(arg0.getPosition())); } @Override public void onMarkerDrag(Marker arg0) {} }); }
public void addCluster(List<GridPoint> complaintDtos) { clearMap(); GoogleMapCluster googleMapCluster; LatLngBounds.Builder builder = new LatLngBounds.Builder(); ClusterManager<GoogleMapCluster> mClusterManager; mClusterManager = new ClusterManager<GoogleMapCluster>(getActivity(), googleMap); googleMap.setOnCameraChangeListener(mClusterManager); googleMap.setOnMarkerClickListener(mClusterManager); for (GridPoint complaintDto : complaintDtos) { googleMapCluster = new GoogleMapCluster( complaintDto.getLocation().getLatitude().doubleValue(), complaintDto.getLocation().getLongitude().doubleValue()); mClusterManager.addItem(googleMapCluster); builder.include(googleMapCluster.getPosition()); } if (complaintDtos.size() > 1) { LatLngBounds bounds = builder.build(); CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0); googleMap.animateCamera(cu); } else if (complaintDtos.size() > 0) { CameraPosition cameraPosition = new CameraPosition.Builder() .target( new LatLng( complaintDtos.get(0).getLocation().getLatitude().doubleValue(), complaintDtos.get(0).getLocation().getLongitude().doubleValue())) .zoom(zoomLevel) .bearing(0) .tilt(45) .build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } markersDisplayed = false; heatmapDisplayed = false; clusterDisplayed = true; }
public void removeCluster() { googleMap.clear(); googleMap.setOnCameraChangeListener(null); googleMap.setOnMarkerClickListener(null); }