objective-c – 如何测试两个CLLocations的平等
发布时间:2020-12-16 02:59:37 所属栏目:百科 来源:网络整理
导读:我有一个isEqual的问题: 代码: if (currentAnchor isEqual:currentBusiness.getCllLocation)) { do a; } else { do b; } currentanchor和currentbusiness.getCllocation是位置 但是如果它们是一样的,为什么要调用函数b?我的代码有问题吗? 解决方法 我假
我有一个isEqual的问题:
代码: if (currentAnchor isEqual:currentBusiness.getCllLocation)) { do a; } else { do b; } currentanchor和currentbusiness.getCllocation是位置 但是如果它们是一样的,为什么要调用函数b?我的代码有问题吗? 解决方法
我假设这两个对象都是类型为CLLocation的,基于getClLocation的名字.
CLLocation对它的isEqual:方法没有任何规定,所以它可能只是继承NSObject的实现,NSObject只是比较对象的指针.如果你有两个不同的对象具有相同的数据,那就是Equal:实现将返回NO.如果你有两个不同的对象,只有一点点变化的位置,他们绝对不会平等. 你可能不想要isEqual:比较位置对象.相反,您可能希望在CLLocation上使用distanceFromLocation:方法.这样的事情会更好: CLLocationDistance distanceThreshold = 2.0; // in meters if ([currentAnchor distanceFromLocation:currentBusiness.getCllLocation] < distanceThreshold) { do a; } else { do b; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |