I am using Mapbox sdk in my project. https://www.mapbox.com/mapbox-ios-sdk/
I have got the basic clustering working but my question is how to i dissolve a cluster further on click of it.
eg. I have a cluster with 8 markers. On click it should further zoom in, not just one level but to a point where all 8 markers are on screen with maximum zoom possible.(some markers out of these 8 can be clustered)
I tried [mapView zoomWithLatitudeLongitudeBoundsSouthWest: CLLocationCoordinate2DMake(south, west) northEast: CLLocationCoordinate2DMake(north, east) animated:YES]; but no success.
This is how ended up doing it:
- (void)tapOnAnnotation:(RMAnnotation *)annotation onMap:(RMMapView *)map {
if (annotation.isClusterAnnotation) {
CLLocationCoordinate2D southwestCoordinate = annotation.coordinate;
CLLocationCoordinate2D northeastCoordinate = annotation.coordinate;
for (RMAnnotation *plot in annotation.clusteredAnnotations) {
CGFloat latititude = plot.coordinate.latitude;
CGFloat longitude = plot.coordinate.longitude;
if (southwestCoordinate.latitude > fabsf(latititude)) southwestCoordinate.latitude = latititude;
if (southwestCoordinate.longitude > fabsf(longitude)) southwestCoordinate.longitude = longitude;
if (northeastCoordinate.latitude < fabsf(latititude)) northeastCoordinate.latitude = latititude;
if (northeastCoordinate.longitude < fabsf(longitude)) northeastCoordinate.longitude = longitude;
}
[self.mapView zoomWithLatitudeLongitudeBoundsSouthWest:southwestCoordinate northEast:northeastCoordinate animated:YES];
}
}
Basically, what's happening here is that I'm storing the outermost region's bounding coordinates southwestCoordinate
and northeastCoordinate
to the tapped annotation (in this case, the cluster). Then, for each annotation within the cluster, we're checking to see if it's absolute distance from that "center" coordinate is the greatest in the group.
Seems to work pretty well for me.