Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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 调用';setRegion';带有无效参数_Iphone_Objective C - Fatal编程技术网

Iphone 调用';setRegion';带有无效参数

Iphone 调用';setRegion';带有无效参数,iphone,objective-c,Iphone,Objective C,只是感觉到了iOS 6特有的奇怪问题。 我使用以下代码在iphonemap中锁定一组给定的地址,它在ios4和ios5上运行良好。但在iOS 6上运行时,在以下堆栈跟踪下崩溃 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“无效区域” 我使用的代码非常简单 `CLLocationCoordinate2D topLeftCoord; topLeftCoord.纬度=-90; topLeftCoord.longitude=180 CLLocation

只是感觉到了iOS 6特有的奇怪问题。 我使用以下代码在iphonemap中锁定一组给定的地址,它在ios4和ios5上运行良好。但在iOS 6上运行时,在以下堆栈跟踪下崩溃

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“无效区域”

我使用的代码非常简单

`CLLocationCoordinate2D topLeftCoord; topLeftCoord.纬度=-90; topLeftCoord.longitude=180

CLLocationCoordinate2D bottomRightCoord; 
bottomRightCoord.latitude = 90; 
bottomRightCoord.longitude = -180; 

for (id<MKAnnotation> annotation in self.mapView.annotations) { 
    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); 
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude); 
    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude); 
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude); 
}
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.5;
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.5;

region = [self.mapView regionThatFits:region];
[self.mapView setRegion:region animated:YES];
cllocationcoordinated2d bottomrightcordinard;
bottomRightCoord.纬度=90;
bottomRightCoord.经度=-180;
对于(self.mapView.annotations中的id注释){
topLeftCoord.longitude=fmin(topLeftCoord.longitude,annotation.coordinate.longitude);
topLeftCoord.latitude=fmax(topLeftCoord.latitude,annotation.coordinate.latitude);
bottomRightCoord.longitude=fmax(bottomRightCoord.longitude,annotation.coordinate.longitude);
bottomRightCoord.latitude=fmin(bottomRightCoord.latitude,annotation.coordinate.latitude);
}
region.span.latitudeDelta=fabs(顶部左坐标纬度-底部右坐标纬度)*1.5;
region.span.longitudeDelta=fabs(底部右坐标经度-顶部左坐标经度)*1.5;
region=[self.mapView RegionAtfits:region];
[self.mapView setRegion:区域动画:是];
`

因此,问题显然在于计算longitudeDelta,因为它试图访问错误的经度+900.000。因此,我改变了主意

以上代码为

region.span.latitudeDelta=self.mapView.region.span.latitudeDelta/2.0002;
region.span.longitudeDelta=self.mapView.region.span.longitudeDelta/2.0002

事故得到了解决,但地图指向了世界上不同的地方。希望你能在这方面传授一些专业知识

我想你已经掌握了:

“问题显然在于计算纵向德尔塔”

我也经历过同样的事情,我所做的很简单:

-(void)myFunction
{
    MKCoordinateRegion region;
    region.span.longitudeDelta = 10;
    region.center = CLLocationCoordinate2DMake(46, 2);
    [map setRegion:region];
}
它在第二次或第三次调用
myFunction
后崩溃,但是当我使用
latitudelta
而不是
longitudeDelta
时,它工作得很好

此外,事故日志为:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    reason: 'Invalid Region <center:+46.00000000, +2.00000000 span:-1.99143220, +10.00000000>'
***由于未捕获异常“NSInvalidArgumentException”而终止应用程序,
原因:“无效区域”
这让我觉得
longitudeDelta
属性有很多漏洞

PS:不需要设置longitudeDelta和latitudelta,因为longitudeDelta=f(latitudelta)
我想你已经知道了:

“问题显然在于计算纵向德尔塔”

我也经历过同样的事情,我所做的很简单:

-(void)myFunction
{
    MKCoordinateRegion region;
    region.span.longitudeDelta = 10;
    region.center = CLLocationCoordinate2DMake(46, 2);
    [map setRegion:region];
}
它在第二次或第三次调用
myFunction
后崩溃,但是当我使用
latitudelta
而不是
longitudeDelta
时,它工作得很好

此外,事故日志为:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    reason: 'Invalid Region <center:+46.00000000, +2.00000000 span:-1.99143220, +10.00000000>'
***由于未捕获异常“NSInvalidArgumentException”而终止应用程序,
原因:“无效区域”
这让我觉得
longitudeDelta
属性有很多漏洞

PS:不需要设置longitudeDelta和latitudeDelta,因为它当然会崩溃

  • 当只有一个
  • 当只有n个相同位置的注释时
  • 只考虑案例,并在该算法失败的情况下有备份区域。

    e、 g

    if(无注释)设置区域:世界
    if(annotationCount<2)setRegion:注释1的区域(跨度为0,05/0,05)
    其他的
    ... 做算法
    如果longitudeDelta==0 setRegion:注释1的区域(跨度为0,05/0,05)
    Else setRegion:就像你现在这样
    
    它当然会崩溃

  • 当只有一个
  • 当只有n个相同位置的注释时
  • 只考虑案例,并在该算法失败的情况下有备份区域。

    e、 g

    if(无注释)设置区域:世界
    if(annotationCount<2)setRegion:注释1的区域(跨度为0,05/0,05)
    其他的
    ... 做算法
    如果longitudeDelta==0 setRegion:注释1的区域(跨度为0,05/0,05)
    Else setRegion:就像你现在这样
    
    您的问题在于减去几个数字。在NSLog语句或NSLog语句中加入一些断点,看看最后一行给出的错误数字在哪里。将每个元素分解为局部变量也会更容易。我认为问题是区域使用0区域调用时的匹配度。你的问题是减去几个数字。在NSLog语句或NSLog语句中加入一些断点,看看最后一行给出的错误数字在哪里。将每个元素分解为局部变量也会更容易。我认为问题是RegionAtFits被0区域调用