CLLocationDistance NaN [英] CLLocationDistance NaN

查看:51
本文介绍了CLLocationDistance NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iPhone快速计算iPhone应用程序中两组坐标点之间的距离

I'm trying to calculate a distance between two sets of coordinate points in an iPhone application on the fly using

 - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location 

我看到我开始在陌生的地方找到NaN,因此用以下硬编码值仔细调查了此事.

I saw that I started getting NaN's in strange places, thus investigated the matter up close, with the following hardcoded values.

CLLocationDistance testDistance;
placeLocation = [[CLLocation alloc] initWithLatitude:12.236533 longitude:11.011419];
userLocation = [[CLLocation alloc] initWithLatitude:12.236533 longitude:11.011419]; 
testDistance = [userLocation getDistanceFrom:placeLocation];
if(isnan(testDistance))
    NSLog(@"ISNaN!");

[placeLocation release];
[userLocation release];

以上多次被调用,在某些情况下,testDistance为NaN.

The above gets called multiple times, and in some situations the testDistance is NaN.

我担心我在这里错过了一些非常简单的东西.有人有什么主意吗?

I fear I'm missing something very simple here. Anyone have any idea?

更新1:

好吧,所以我将上面的代码移到了一个新项目中(将所有内容放入应用程序委托中),将其循环了100次,一切都很好.因此,这表明问题是与项目相关的,但这几乎没有帮助...因为所有变量都在1个函数的范围内.

Ok, so I've moved the above code into a new project (put everything in the app delegate), looped it for 100 times and all is fine. This thus suggests that the problem is project related, but this helps very little... since all the variables are in the scope of 1 function.

解决方案:

好的,这似乎是模拟器错误.相同的代码构建在设备上可以很好地运行.案例解决了.

推荐答案

解决方案:

好的,这似乎是模拟器错误.相同的代码构建在设备上可以很好地运行.案例解决了,您如何向Apple提交错误?

OK, this seems to be a simulator bug. The same code build runs perfectly fine on the device. Case solved, how do you file a bug with Apple?

这篇关于CLLocationDistance NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆