2013-08-13 3 views

Antwort

5

Wie über diese beiden Methoden aus MapKit Klasse:

1) sichtbar Rechteck Karte Erhalten Sie mit:

@property(nonatomic, readonly) CGRect annotationVisibleRect 

http://developer.apple.com/library/ios/DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instp/MKMapView/annotationVisibleRect

2) Dann Anmerkung erhalten NSSet von Parameter-Rechteck:

- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect 

http://developer.apple.com/library/ios/DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instm/MKMapView/annotationsInMapRect:

So würde ich so etwas wie dies erwartet:

-(void)getAnotationsInVisibleMapRectangle 
{ 
    NSSet *annotationSet = [myMapView annotationsInMapRect:myMapView.annotationVisibleRect]; 

    // print number of annotations 
    NSLog(@"Number of annotations in rect: %d", annotationSet.count); 

    // this will return an array from the NSSet 
    NSArray *annotationArray = [annotationSet allObjects]; 
} 

Does diese Hilfe?

+0

Es ist schön, muss aber CGRect (myMapView.annotationVisibleRect) zu MKMapRect konvertieren? "annotationInMapRect (MKMapRect)" ... – Nubaslon

+0

Danke! =) Es hilft mir) und ich benutze "visibleMapRect" anstelle von "annotationVisibleRect" – Nubaslon

+0

hat mir geholfen Los..thank you –

9

Wie für eine rasche 2.0 ich in der Regel diese mapView Erweiterung verwenden, um alle aktuell sichtbaren Anmerkungen als ein Array von MKAnnotations zu bekommen:

extension MKMapView { 
    func visibleAnnotations() -> [MKAnnotation] { 
     return self.annotationsInMapRect(self.visibleMapRect).map { obj -> MKAnnotation in return obj as! MKAnnotation } 
    } 
} 
+0

extrem nützlich. –

+0

Wenn sich einige Anmerkungen am Bildschirmrand befinden, funktioniert das nicht – vinbhai4u

+0

Für dieses spezielle Szenario könnten Sie statt des standardmäßigen visibleMapRect ein größeres MapRect übergeben. –

Verwandte Themen