我有一个使用MKMapView的应用程序。在我的应用程序中,我已经声明了一个数组,它将保存API的响应。来自API的数据是要固定在地图中的作业(聚类注释)。保存来自API的作业的数组将/需要通过地图中可见的作业引脚进行过滤。我能够过滤坐标(在地图中可见或不可见)但我在将数据(可见的坐标)存储在新数组中时遇到了麻烦。
这是我到目前为止所拥有的: 在我的mapview中的regionDidChangeAnimated中
[ar objectAtIndex:0];
NSMutableDictionary *visibleJobs;
for(NSDictionary *loc in ar)
{
CLLocationDegrees Lat = [[[loc objectForKey:@"sub_slots"] objectForKey:@"latitude"] doubleValue];
CLLocationDegrees longTitude = [[[loc objectForKey:@"sub_slots"] objectForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D point = CLLocationCoordinate2DMake(Lat, longTitude);
MKMapPoint mkPoint = MKMapPointForCoordinate(point);
BOOL contains = MKMapRectContainsPoint(mapView.visibleMapRect, mkPoint);
if(contains)
{
NSLog(@"Contains:1");
}
else
{
NSLog(@"Contains:0");
}
}
非常感谢任何帮助。 谢谢!
答案 0 :(得分:1)
为什么不使用NSMutableArray
试试这个
NSMutableArray *visibleJobs = [[NSMutableArray alloc]init];
for(NSDictionary *loc in ar)
{
CLLocationDegrees Lat = [[[loc objectForKey:@"sub_slots"] objectForKey:@"latitude"] doubleValue];
CLLocationDegrees longTitude = [[[loc objectForKey:@"sub_slots"] objectForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D point = CLLocationCoordinate2DMake(Lat, longTitude);
MKMapPoint mkPoint = MKMapPointForCoordinate(point);
BOOL contains = MKMapRectContainsPoint(mapView.visibleMapRect, mkPoint);
if(contains)
{
NSLog(@"Contains:1");
[visibleJobs addObject:loc];
}
else
{
NSLog(@"Contains:0");
}
}
现在,可见作业数组包含当前在地图上可见的所有引脚数据的字典