2012-09-04 36 views
2

我正在创建一个应用程序,需要确定我的当前位置(recD in didUpdateLocation :)是否存在于我拥有的一组地理坐标中。现在我明白,比较平等的双/浮点值可能会出错,因为地理坐标中涉及的精度非常高。 GPS中的轻微不准确可能导致我的算法偏离轨道。因此我需要将它与一些误差范围进行比较。iOS比较GPS位置

如何比较2个CLLocations和误差范围?或者确定位置阅读中的错误(我不认为这是可能的,因为CLLocationManager会纠正它)。

感谢提前:)

+0

【你有什么试过?】(http://whathaveyoutried.com)检查你的点是否在一个正方形或圆形的边界或半径为误差范围内? –

回答

4

在每个CLLocation实例有声明为@property(readonly, nonatomic) CLLocationAccuracy horizontalAccuracy;属性你可以做的是使例程,如:

-(BOOL)isLocation:(CLLocation*)location inRangeWith:(CLLocation*)otherLocation{ 
    CLLocationDistance delta = [location distanceFromLocation:otherLocation]; 
    return (delta < location.horizontalAccuracy); 
} 

可以做得更复杂的逻辑,因为这两个地方有属性。 ..

干杯。 【ツ】

+0

嗨阿里尔。 .horizo​​ntalAccuracy是一个很好的指针。我可以用,thanx。但我的根本问题是我想避免使用distanceFromLocation:在那里的任何解决方法? – ameyazing

+0

你可以用坐标来计算三角洲,但它会更复杂一些,因为根据赤道的距离,一个坐标角度的实际距离以米为单位是不同的。 无论如何,据我可以告诉'distanceFromLocation:'没有太多的电力或CPU消耗... – Ariel

1

可以使用CoreLocation方法distanceFromLocation:找到用户的位置和另一点之间的距离。如果距离小于您决定的任何阈值,则可以假定位置相同。

CLLocationDistance threshold = 5.0; // threshold distance in meters 

// note: userLocation and otherLocation are CLLocation objects 
if ([userLocation distanceFromLocation:otherLocation] <= threshold) { 
    // same location 
} 
+0

嗨jonkroll,我没有看过任何定量的研究证明了这一点,但从它的外观来看,Haversine公式看起来很复杂,距离从位置:最有可能用这个来计算2 lat-long之间的距离。我想避免在每个经纬度上使用该函数。任何解决方法? – ameyazing