开发者

How to select annotations of specific class in visible map rect

I am trying to implement the method below which basically populates my array with the annotations visible in the current map rect.

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    self.LocationSet = [self.mapView annotationsInMapRect:self.mapView.visibleMapRect];

    self.LocationArray = [self.nearbyCarParksSet allObjects];

}

What is the right way to select only a certain class of annotations which I want to include in the set/array? For example, in the current map view I might have annotations belonging to a "Restaurant" class, a "carpark" class, a "petrol station" class, etc., and I only want to store annotations belonging to开发者_如何学运维 the "Restaurant" class. What is the best approach?


Assuming that locationSet has all the annotation derived from the first call in the method above. You can get all annotations of type using,

restaurantSet = [locationSet objectsPassingTest:^(id obj, BOOL *stop){
    return [obj isMemberOfClass:[YourAnnotationSubclass class]];
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜