Reputation: 137
When didTap cluster function is called, it zooms the camera to one of the markers present inside the cluster but I want to show all the markers that were in that cluster and focus the camera on those markers.
I was able to achieve this in android. However in iOS the google utils sdk doesn't provide a way to get all the items present in a cluster object.
Here's the android code
mClusterManager
.setOnClusterClickListener(new
ClusterManager.OnClusterClickListener<Service_Provider>() {
@Override
public boolean onClusterClick(final Cluster<Service_Provider> cluster) {
LatLngBounds.Builder builder = LatLngBounds.builder();
for (ClusterItem item : cluster.getItems()) {
builder.include(item.getPosition());
Log.w(TAG, "Clicked Cluster Item name: " + item.getTitle());
}
final LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
return true;
}
});
What I have tried in iOS so far
func clusterManager(_ clusterManager: GMUClusterManager, didTap cluster:
GMUCluster) -> Bool {
print("Did tap cluster")
let newCamera = GMSCameraPosition.camera(withTarget: cluster.position,
zoom: mapView.camera.zoom +1)
let update = GMSCameraUpdate.setCamera(newCamera)
mapView.moveCamera(update)
}
Any help is appreciated.
TIA
Upvotes: 1
Views: 1057
Reputation: 874
func showBoundBox( _ list : [CLLocationCoordinate2D]){
var bounds = GMSCoordinateBounds()
for location in list {
bounds = bounds.includingCoordinate(location)
}
let update = GMSCameraUpdate.fit(bounds, withPadding: 100)
map.animate(with: update)
}
Upvotes: 3