gpt4 book ai didi

objective-c - 如何测试两个 CLLocations 的相等性

转载 作者:太空狗 更新时间:2023-10-30 03:25:06 25 4
gpt4 key购买 nike

我对 isEqual 有疑问:

代码:

 if (currentAnchor isEqual:currentBusiness.getCllLocation))
{
do a;
}
else
{
do b;
}

currentanchor 和 currentbusiness.getClocation 是位置

但如果它们相同,为什么调用函数b?我的代码有问题吗?

最佳答案

我假设这两个对象都是 CLLocation 类型,基于 getClLocation 的名称。

CLLocation 没有关于它的 isEqual: 方法做什么的任何规范,所以它很可能只是继承了 NSObject 的实现,它简单地比较对象的指针。如果您有两个具有相同数据的不同对象,则 isEqual: 实现将返回 NO。如果你有两个不同的物体,只是位置略有不同,它们肯定不会相等。

在比较位置对象时,您可能不需要 isEqual:。相反,您可能想在 CLLocation 上使用 distanceFromLocation: 方法。这样的事情会更好:

CLLocationDistance distanceThreshold = 2.0; // in meters
if ([currentAnchor distanceFromLocation:currentBusiness.getCllLocation] < distanceThreshold)
{
do a;
}
else
{
do b;
}

关于objective-c - 如何测试两个 CLLocations 的相等性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6529726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com