2011-08-17 68 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,

阿克沙伊