Ios MKCoordinateRegionMakeWithDistance-throws“;线程1:信号SIGABRT“;
我有一个新的问题,我不知道为什么。。。我的进一步解决方案由Rob发布。我喜欢他的工作,在iOS 6.1升级之前,他的工作非常出色Ios MKCoordinateRegionMakeWithDistance-throws“;线程1:信号SIGABRT“;,ios,ios6,mkmapview,mapkit,Ios,Ios6,Mkmapview,Mapkit,我有一个新的问题,我不知道为什么。。。我的进一步解决方案由Rob发布。我喜欢他的工作,在iOS 6.1升级之前,他的工作非常出色 - (void)loadKml:(NSURL *)url { // parse the kml Parser *parser = [[Parser alloc] initWithContentsOfURL:url]; parser.rowElementName = @"Placemark"; parser.elementNames =
- (void)loadKml:(NSURL *)url
{
// parse the kml
Parser *parser = [[Parser alloc] initWithContentsOfURL:url];
parser.rowElementName = @"Placemark";
parser.elementNames = @[@"name", @"Snippet", @"coordinates", @"description"];
parser.attributeNames = @[@"img src="];
[parser parse];
// add annotations for each of the entries
for (NSDictionary *locationDetails in parser.items)
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.title = locationDetails[@"name"];
annotation.subtitle = locationDetails[@"Snippet"];
NSArray *coordinates = [locationDetails[@"coordinates"] componentsSeparatedByString:@","];
annotation.coordinate = CLLocationCoordinate2DMake([coordinates[1] floatValue], [coordinates[0] floatValue]);
[self.mapView addAnnotation:annotation];
}
// update the map to focus on the region that encompasses all of your annotations
MKCoordinateRegion region;
if ([self.mapView.annotations count] > 1)
{
region = [self regionForAnnotations:self.mapView.annotations];
region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05)); // expand the region by 5%
}
else
{
id<MKAnnotation> annotation = self.mapView.annotations[0];
region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0); // >>>this line throws: "Thread 1: signal SIGABRT"<<<
}
[self.mapView setRegion:region animated:YES];
}
有几点想法:
IBOutlet
与mapView
已连接?如果self.mapView
为nil
,应用程序可能会崩溃注释。协调以确保获得有效的结果?可能有一个MKUserLocation
还没有有效值
if ([self.mapView.annotations count] > 0)
{
MKCoordinateRegion region;
if ([self.mapView.annotations count] > 1)
{
region = [self regionForAnnotations:self.mapView.annotations];
region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05)); // expand the region by 5%
}
else
{
id<MKAnnotation> annotation = self.mapView.annotations[0];
region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0);
}
[self.mapView setRegion:region animated:YES];
}
正在检索您的图像URL吗?我认为这应该是:
parser.attributeNames = @[@"src"];
也许您对解析器做了一些更改,但是didStartElement
的attributeDict
将永远不会有一个对象由img src=
设置关键字。如果XML标记是
,那么您要查找的属性名称就是src
IBOutlet
与mapView
已连接?如果self.mapView
为nil
,应用程序可能会崩溃注释。协调以确保获得有效的结果?可能有一个MKUserLocation
还没有有效值
if ([self.mapView.annotations count] > 0)
{
MKCoordinateRegion region;
if ([self.mapView.annotations count] > 1)
{
region = [self regionForAnnotations:self.mapView.annotations];
region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05)); // expand the region by 5%
}
else
{
id<MKAnnotation> annotation = self.mapView.annotations[0];
region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0);
}
[self.mapView setRegion:region animated:YES];
}
正在检索您的图像URL吗?我认为这应该是:
parser.attributeNames = @[@"src"];
也许您对解析器做了一些更改,但是didStartElement
的attributeDict
将永远不会有一个对象由img src=
设置关键字。如果XML标记是
,那么您要查找的属性名称就是src
你有没有检查过,在那一点上你实际上有一个注释要使用?可能您的
self.mapView.annotations[0]
返回的值为零。您是否检查过您当时是否有要使用的注释?也许你的self.mapView.annotations[0]
返回了零。1。)是的,钩住了2。)我不知道如何测试它3。)我尝试了代码,我的应用程序将运行没有错误,但有一个空映射4。)更正:-)@curtismoschmidt 2。将NSLog语句放在给出异常的行之前。或者更好的方法是在代码中设置一个断点并单步执行该代码。(请参阅)当您遇到这样的异常时,总是因为某个无效变量被传递给某个方法/函数。我用注释标记的代码行,请参阅:region=mkcoordinaeregionmakewithdistance(annotation.coordinate,100.0,100.0)代码>如果我做了NSLog(@“%@”,annotation.coordinate)代码>在这行前后,我将得到一个警告:格式指定类型“id”,但参数的类型是CCLocationCoordinate2D
我有点confused@CurtisTimoSchmidt是的,所以你可以做NSLog(@“%@:%f,%f”,注解,注解。坐标。纬度,注解。坐标。经度)不幸的是,它什么也没有带来。显示的日志中没有详细信息。应用程序总是在id annotation=self.mapView.annotations[0]之后终止代码>1。)是挂接2。)我不知道如何测试它3。)我尝试了代码,我的应用程序将运行没有错误,但有一个空映射4。)更正:-)@curtismoschmidt 2。将NSLog语句放在给出异常的行之前。或者更好的方法是在代码中设置一个断点并单步执行该代码。(请参阅)当您遇到这样的异常时,总是因为某个无效变量被传递给某个方法/函数。我用注释标记的代码行,请参阅:region=mkcoordinaeregionmakewithdistance(annotation.coordinate,100.0,100.0)代码>如果我做了NSLog(@“%@”,annotation.coordinate)代码>在这行前后,我将得到一个警告:格式指定类型“id”,但参数的类型是CCLocationCoordinate2D
我有点confused@CurtisTimoSchmidt是的,所以你可以做NSLog(@“%@:%f,%f”,注解,注解。坐标。纬度,注解。坐标。经度)不幸的是,它什么也没有带来。显示的日志中没有详细信息。应用程序总是在id annotation=self.mapView.annotations[0]之后终止代码>