I'm trying to iron out a bug in my map app. I've added working code that (1) determines the number of annotations displayed on the map and (2) builds a NSSet of those annotations. When I return an array from the NSSet and NSLog the contents of the array, I don't understand the output. Can someone help me understand the meaning of the array output and how that information relates to the latitude/longitude coordinates originally plotted when the map was generated? I'm using Xcode 7.1
Sample code:
-(void)getAnotationsInVisibleMapRectangle{
MKMapRect visibleMapRect = mapView.visibleMapRect;
NSSet *visibleAnnotations = [mapView annotationsInMapRect:visibleMapRect];
// print number of annotations
NSLog(@"Number of annotations in rect: %lu", (unsigned long)visibleAnnotations.count);
// this will return an array from the NSSet
NSArray *annotationArray = [visibleAnnotations allObjects];
NSLog(@"%@", annotationArray);
}
Sample output when the array is logged:
2015-10-30 14:22:45.635 [17633:6301958] Number of annotations in rect: 0
2015-10-30 14:22:45.635 [17633:6301958] (
)
2015-10-30 14:22:58.707 [17633:6301958] Number of annotations in rect: 6
2015-10-30 14:22:58.708 [17633:6301958] (
"< DisplayMap: 0x7f84e7947740 >",
"< DisplayMap: 0x7f84e722a310 >",
"< DisplayMap: 0x7f84e791a9f0 >",
"< DisplayMap: 0x7f84e6f47820 >",
"< DisplayMap: 0x7f84e7910950 >",
"< DisplayMap: 0x7f84e7460730 >",
答案 0 :(得分:0)
Annotations displayed on map is object of some particular class, in your case its of type DisplayMap. Since there are 6 annotations, it is displaying memory locations of all 6 annotation objects along with its class type(i.e DisplayMap). Output does not reveal any information about latitude and longitude at which annotation is to be displayed. However you can get coordinates of annotation by accessing "coordinate" property of annotation object.