gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:58:57 24 4
gpt4 key购买 nike

我在项目中使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com