ios - Mapbox如何在单击时解散群集

标签 ios xcode map mapbox markerclusterer

我在项目中使用Mapbox SDK。 https://www.mapbox.com/mapbox-ios-sdk/

我已经完成了基本的集群工作,但是我的问题是如何在单击它时进一步分解集群。

例如。我有一个带有8个标记的群集。单击时,它应该进一步放大,不仅是一个级别,而且还可以放大到屏幕上所有8个标记的位置,并可能实现最大缩放(可以将这8个标记中的一些标记聚类)

我试过了
[mapView zoomWithLatitudeLongitudeBoundsSouthWest:CLLocationCoordinate2DMake(南,西)
northEast:CLLocationCoordinate2DMake(北,东),动画:是];
但没有成功。

最佳答案

最终是这样的:

- (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];

   }
}

基本上,这里发生的是我将最外层区域的边界坐标southwestCoordinatenortheastCoordinate存储到轻击的批注(在本例中为簇)。然后,对于集群中的每个注释,我们要检查它与该“中心”坐标的绝对距离是否在组中最大。

似乎对我来说很好。

关于ios - Mapbox如何在单击时解散群集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24261745/

相关文章:

android - 获取MD5指纹的问题

python - Hadoop与Hadoop上的图形路径

r - 用 R 创建大圆图

ios - 从 pod 安装框架后,无法在 Swift 项目中导入类

ios - 如何将自定义结构数组保存到 plist swift

ios - 选择 HealthKit HKActivitySummary -> "NSInvalidArgumentException", "startDateComponents: Date components require a calendar."

c++ - macosx maverick 上的 cmake,如何强制包含/usr/include

iphone - 以编程方式在主屏幕上启动网络应用程序?

ios - XCode 导航 - 方法列表

ios - 删除对象并创建同名的新对象,保留引用旧对象