How can I reduce the number of annotations on a map?

后端 未结 6 1471
时光说笑
时光说笑 2020-12-13 11:03

I\'m coding a map view with around 900 annotations. Having this many annotations on a map make the performance suffer, so I\'d like to reduce it to about 300 at a time. The

6条回答
  •  青春惊慌失措
    2020-12-13 11:08

    Here's a code snippet that takes an MKAnnotation's coordinates, convert it to a CGPoint relative to the MKMapView, and logs what's the underlying view at that CGPoint.

    CGPoint pinPoint = [mapView convertCoordinate:pinView.annotation.coordinate toPointToView:mapView];
    NSLog(@"pointing to %@", [[mapView hitTest:pinPoint withEvent:nil] description]);
    

    Put that inside a loop that iterates through all your pins. If the underlying view is another MKAnnotation instance, then hide that pin.

    if([[mapView hitTest:pinPoint withEvent:nil] isKindOfClass:[FFMapPinView class]])
        pinView.hidden = YES;
    

    For this to work properly, you need the pinsArray to be ordered so that index 0 is the frontmost pin.

提交回复
热议问题