如何查找mapview引脚是否重叠和缩放?

时间:2012-05-07 14:06:37

标签: iphone objective-c ios mkmapview mkannotation

我想放大,如果有多个引脚重叠,并且它们不只是想显示一些细节页面。

我想出了一个解决方案,但它大部分时间都有效,但并不总是

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
     MKMapPoint annotationPoint = MKMapPointForCoordinate(view.annotation.coordinate);
    MKMapRect mRect = self.mapView.visibleMapRect;
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, (mRect.size.width/view.frame.size.width)*[self.mapView currentZoomLevel]*10 , (mRect.size.height/view.frame.size.height)*[self.mapView currentZoomLevel]*10 );    
    NSLog(@"point rect origin %f ..%f.....size %f....%f",pointRect.origin.x, pointRect.origin.y, pointRect.size.width, pointRect.size.height);
    NSSet * AnnSet = [self.mapView annotationsInMapRect:pointRect];
    NSLog(@"annotations obtained :%i",[[AnnSet allObjects] count]);
    //    [self.mapView setVisibleMapRect:pointRect animated:YES];

    NSLog(@"max zoom level :%i",[self.mapView currentZoomLevel]);
    if ([[AnnSet allObjects] count]>1 && [self.mapView currentZoomLevel]<19 ) {//zoom it
        [self.mapView setCenterCoordinate:view.annotation.coordinate zoomLevel:[self.mapView currentZoomLevel]+1 animated:YES];
        [self.mapView deselectAnnotation:view.annotation animated:NO];
    }
    else{
  //Show detail page
}
}

问题似乎是我如何生成pointRect。

MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, (mRect.size.width/view.frame.size.width)*[self.mapView currentZoomLevel]*10 , (mRect.size.height/view.frame.size.height)*[self.mapView currentZoomLevel]*10 );   

欢迎任何形式的帮助:)

0 个答案:

没有答案