[英]ios: predict if two annotation views would overlap each other
我正在開發一些MKMapView
邏輯。 我的地圖視圖上有很多注釋。 如果那些注解視圖相互重疊,並顯示帶更改的注解視圖,則我需要在一個位置組成幾個位置。 因此,我應該預測這種情況,並且僅需要通過注釋的位置屬性和當前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;
}
我也擔心這個解決方案,因為我需要在每次縮放更改時重新加載注釋和那些視圖。
我怎樣才能更好地做到這一點? 注釋視圖群集是否有任何默認解決方案?
現有的所有庫都不適合我的需要,它們都適用於區域,但是僅當注釋重疊時,我才需要對注釋進行分組。 另外,我不需要太多注釋,因此不需要性能優化。 因此,我找到了一些解決方案,這總比沒有好。
- (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.