2011-08-17 70 views
1

我想查找到某个位置的距离以及该设备与该位置相关的朝向。我有距离工作,但无法找到如何找到位置的方式。查找设备是否指向正确的标题/方向?

_theLocation = [[CLLocation alloc]initWithLatitude:-41.561004 longitude:173.849030]; 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    CLLocationDistance meters = [newLocation distanceFromLocation:_theLocation] * 0.000621371192; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading 
{ 
    NSString *str = [NSString stringWithFormat:@"Heading = %.f", newHeading.trueHeading]; 
} 

是否可以从我们的位置找到标题_theLocation

+1

你需要计算两个坐标之间的 “轴承”。没有内置的功能,所以需要编写自己的。请参阅[this](http://stackoverflow.com/questions/3198186/calculate-compass-heading-to-a-cllocation-haversine-functions-for-ios)和[this](http://stackoverflow.com/问题/ 3925942/cllocation类别换计算轴承-W-半正矢函数)。 – Anna 2011-08-17 12:56:28

+0

谢谢你将看看这些链接。 – daidai 2011-08-17 13:21:04

回答

0

难道你不能简单地捕获设备的位置在两个实例&找出方向与位置?

不是一个完整的解决方案,但假设设备只沿着加入设备&的线路移动的位置,则可以使用– distanceFromLocation:。如果在两个实例中捕获距离该位置的距离&看看后者的值是否小于前者,则可以推断出该设备已经靠近该位置。

事实上,从你的问题看来,你想要确定设备是否已经移近了位置(而不是确切的方向,比如说N或NE)。如果是这样,那么这应该工作。

HTH,

阿克沙伊