Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 仅在区域内进行注释_Iphone_Mkannotation_Region - Fatal编程技术网

Iphone 仅在区域内进行注释

Iphone 仅在区域内进行注释,iphone,mkannotation,region,Iphone,Mkannotation,Region,如何仅加载显示区域内的注释?目前,我使用此方法加载所有注释 - (void)reloadAnnotatons { NSFetchRequest *request = [[NSFetchRequest alloc] init]; request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context]; request.predicate = [NSPre

如何仅加载显示区域内的注释?目前,我使用此方法加载所有注释

- (void)reloadAnnotatons
{
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > 0) AND (longitude > 0)"];

    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];
}
关于如何删除显示器外的所有注释并加载其他注释,有什么想法或好的文档吗

非常感谢

编辑:

我实际上已经找到了一个解决方案,但不知何故,它并不完全有效。我检查区域是否已更改

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self reloadAnnotatons];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self reloadAnnotatons];
}
然后我得到max/min lat/long并将其从coredata中拉出

- (void)reloadAnnotatons
{
    double minLat = self.mapView.region.center.latitude - (self.mapView.region.span.latitudeDelta / 2);
    double maxLat = self.mapView.region.center.latitude + (self.mapView.region.span.latitudeDelta / 2);
    double minLon = self.mapView.region.center.longitude - (self.mapView.region.span.longitudeDelta / 2);
    double maxLon = self.mapView.region.center.longitude + (self.mapView.region.span.longitudeDelta / 2);

    NSLog(@"%f %f %f %f",minLat,maxLat,minLon,maxLon);

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > %f AND latitude < %f) AND (longitude > %f AND longitude < %f)",minLat,maxLat,minLon,maxLon];

    //NSLog(@"%@",[self.context executeFetchRequest:request error:NULL]);

    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];
}
- (void)reloadAnnotatons
{
    double minLat = self.mapView.region.center.latitude - (self.mapView.region.span.latitudeDelta / 2);
    double maxLat = self.mapView.region.center.latitude + (self.mapView.region.span.latitudeDelta / 2);
    double minLon = self.mapView.region.center.longitude - (self.mapView.region.span.longitudeDelta / 2);
    double maxLon = self.mapView.region.center.longitude + (self.mapView.region.span.longitudeDelta / 2);


    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > %lf AND latitude < %lf) AND (longitude > %lf AND longitude < %lf)",minLat,maxLat,minLon,maxLon];


    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];
}
我一放大,它就得到了物体。尽管它以前应该已经找到了

2011-09-07 08:48:35.363 CaveConditions[9028:707] 46.277977 48.327505 5.453421 7.806564
2011-09-07 08:48:35.376 CaveConditions[9028:707] (
    "<Cave: 0x1d8710> (entity: Cave; id: 0x1cdd10 <x-coredata://738720B4-DCF4-40BA-BD83-A459CECE5F29/Cave/p2> ; data: <fault>)",
    "<Cave: 0x1941c0> (entity: Cave; id: 0x1d1e70 <x-coredata://738720B4-DCF4-40BA-BD83-A459CECE5F29/Cave/p47> ; data: <fault>)",
    "<Cave: 0x190200> (entity: Cave; id: 0x1e62b0 <x-coredata://738720B4-DCF4-40BA-BD83-A459CECE5F29/Cave/p57> ; data: <fault>)",
    "<Cave: 0x1e4960> (entity: Cave; id: 0x1a1560 <x-coredata://738720B4-DCF4-40BA-BD83-A459CECE5F29/Cave/p67> ; data: <fault>)",
2011-09-07 08:48:35.363洞穴条件[9028:707]46.277977 48.327505 5.453421 7.806564
2011-09-07 08:48:35.376警告条件[9028:707](
“(实体:Cave;id:0x1cdd10;数据:)”,
“(实体:Cave;id:0x1d1e70;数据:)”,
“(实体:Cave;id:0x1e62b0;数据:)”,
“(实体:Cave;id:0x1a1560;数据:)”,
它实际上是在我使用sql直接查询sqllite数据库时找到的

SELECT * 
FROM caves
WHERE (
latitude > 43.930069
AND latitude < 50.169209
)
AND (
longitude > 3.078351
AND longitude < 10.207223
)
选择*
来自洞穴
在哪里(
纬度>43.930069
纬度<50.169209
)
及(
经度>3.078351
经度<10.207223
)

为什么会这样?

作为默认地图视图,仅加载显示器内(即屏幕上)的批注。如果只移动屏幕,则可以使用批注的重用标识符重用批注。因此,从技术上讲,您不需要删除显示器外的批注

苹果文档信息

由于注释视图仅在屏幕上时才需要,因此 MKMapView类提供了将注释视图排队的机制 未使用的。可以使用具有重用标识符的注释视图 当他们离开时,地图视图会在内部分离和排队 此功能通过只保留一小部分内存来提高内存使用率 一次在内存中并通过循环 视图。它还通过 减少了在地图滚动时创建新视图的需要


事实上,我找到了所有这些问题的解决方案。我跟踪该地区是否发生了变化

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self reloadAnnotatons];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self reloadAnnotatons];
}
然后我得到max/min lat/long并将其从coredata中拉出

- (void)reloadAnnotatons
{
    double minLat = self.mapView.region.center.latitude - (self.mapView.region.span.latitudeDelta / 2);
    double maxLat = self.mapView.region.center.latitude + (self.mapView.region.span.latitudeDelta / 2);
    double minLon = self.mapView.region.center.longitude - (self.mapView.region.span.longitudeDelta / 2);
    double maxLon = self.mapView.region.center.longitude + (self.mapView.region.span.longitudeDelta / 2);

    NSLog(@"%f %f %f %f",minLat,maxLat,minLon,maxLon);

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > %f AND latitude < %f) AND (longitude > %f AND longitude < %f)",minLat,maxLat,minLon,maxLon];

    //NSLog(@"%@",[self.context executeFetchRequest:request error:NULL]);

    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];
}
- (void)reloadAnnotatons
{
    double minLat = self.mapView.region.center.latitude - (self.mapView.region.span.latitudeDelta / 2);
    double maxLat = self.mapView.region.center.latitude + (self.mapView.region.span.latitudeDelta / 2);
    double minLon = self.mapView.region.center.longitude - (self.mapView.region.span.longitudeDelta / 2);
    double maxLon = self.mapView.region.center.longitude + (self.mapView.region.span.longitudeDelta / 2);


    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > %lf AND latitude < %lf) AND (longitude > %lf AND longitude < %lf)",minLat,maxLat,minLon,maxLon];


    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];
}
-(void)重新加载注释
{
double minLat=self.mapView.region.center.latitude-(self.mapView.region.span.latitudeDelta/2);
double maxLat=self.mapView.region.center.latitude+(self.mapView.region.span.latitudeDelta/2);
double minLon=self.mapView.region.center.longitude-(self.mapView.region.span.longitudeDelta/2);
double maxLon=self.mapView.region.center.longitude+(self.mapView.region.span.longitudeDelta/2);
NSFetchRequest*request=[[NSFetchRequest alloc]init];
request.entity=[NSEntityDescription entityForName:@“Cave”inManagedObjectContext:self.context];
request.predicate=[NSPredicate predicate格式:@“(纬度>%lf,纬度<%lf)和(经度>%lf,经度<%lf)”,minLat,maxLat,minLon,maxLon];
[self.mapView addAnnotations:[self.context executeFetchRequest:请求错误:NULL]];
}

我同意这一点。但一开始我仍然从CoreData加载所有内容。如果可能的话,我想限制这一点。我的建议是,您必须检查CoreData返回的坐标是否在当前地图视图区域可见,如果可以,请将坐标添加到注释中。如果我的假设正确,请访问此链接找到了一个解决方案。我编辑了我以前的帖子。唯一的问题是它并不完美。你知道吗?