简体   繁体   English

ios:预测两个注释视图是否会相互重叠

[英]ios: predict if two annotation views would overlap each other

I'm developing some MKMapView logic. 我正在开发一些MKMapView逻辑。 There are many annotations on my map view. 我的地图视图上有很多注释。 I need to compose few locations in one if those annotation views would overlap each other, and display Annotation view with changes. 如果那些注解视图相互重叠,并显示带更改的注解视图,则我需要在一个位置组成几个位置。 So I should predict that case, and I need to determinate that only from annotations' location properties and current MKMapView 's zoom. 因此,我应该预测这种情况,并且仅需要通过注释的位置属性和当前MKMapView的缩放来确定这种情况。

- (BOOL)shouldAlert:(CoordinatesAlert *)alert1 beInGroupWithAlert:(CoordinatesAlert *)alert2 {
    // somehow calculate current map view zoom
    CGFloat zoom = ...
    if ([alert1.location distanceFromLocation:alert2.location] / zoom < kSomeCoeficient) {
        return YES;
    }
    return NO;
}

Also I worried about this solution because I need to reload annotations and those views on every zoom change. 我也担心这个解决方案,因为我需要在每次缩放更改时重新加载注释和那些视图。

How can I do this in better way? 我怎样才能更好地做到这一点? Is there any default solution for annotation views clustering? 注释视图群集是否有任何默认解决方案?

All of exist libraries do not suit for my needs, they all works with areas but I need to group annotations only if they would be overlapped. 现有的所有库都不适合我的需要,它们都适用于区域,但是仅当注释重叠时,我才需要对注释进行分组。 Also I do not need so many annotations, so i do not need performance optimization. 另外,我不需要太多注释,因此不需要性能优化。 So, I've found some solution, it is better then nothing. 因此,我找到了一些解决方案,这总比没有好。

- (BOOL)isViewForLocation:(CLLocation *)location1 overlappedByViewForLocation:(CLLocation *)location2 {
    const CLLocationDegrees deltaLatitude = ABS(location1.coordinate.latitude - location1.coordinate.latitude);
    const CLLocationDegrees deltaLongitude = ABS(location2.coordinate.longitude - location2.coordinate.longitude);
    const CLLocationDegrees mapAreaLatitude = self.mapView.region.span.latitudeDelta;
    const CLLocationDegrees mapAreaLongitude = self.mapView.region.span.longitudeDelta;

    return (deltaLatitude / mapAreaLatitude) < (kAnnotationTapArea.size.height / self.mapView.frame.size.height)
    && (deltaLongitude / mapAreaLongitude) < (kAnnotationTapArea.size.width / self.mapView.frame.size.width);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM