2014-10-23 4 views
0

로직을 개발 중입니다. MKMapView 로직입니다. 내지도보기에는 많은 주석이 있습니다. 해당 주석보기가 서로 겹칠 경우 하나의 위치를 ​​작게 작성해야하며 변경 사항이있는 주석보기를 표시해야합니다. 그래서 나는 그 경우를 예측해야하고, 주석의 위치 속성과 현재 MKMapView의 확대/축소에서만 결정해야합니다. 나는 모든 줌 변화에 주석하고 그 전망을 다시해야하기 때문에 ios : 두 개의 주석보기가 서로 겹칠 지 예측합니다.

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

또한 나는이 솔루션에 대한 걱정.

더 좋은 방법으로 어떻게하면됩니까? 어노테이션 뷰 클러스터링을위한 기본 솔루션이 있습니까?

+0

라이브러리는 [OCMapView (https://github.com/yinkou/OCMapView) 또는 [킹핀 (https://github.com/itsbonczek/kingpin)로 존재한다. 그것들은 최고가 아니지만 Google을 둘러보고 귀하의 필요에 맞는 것을 찾을 수 있습니다. – rdurand

+0

CoordinatesAlert이란 무엇입니까? –

+0

@DavidAnsermot – BergP

답변

0

존재하는 모든 라이브러리는 내 필요에 적합하지 않으며 모든 영역과 함께 작동하지만 중복되는 경우에만 주석을 그룹화해야합니다. 또한 너무 많은 주석이 필요하지 않으므로 성능 최적화가 필요하지 않습니다. 그래서 몇 가지 해결책을 찾았습니다.

- (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); 
}