在我的應用程序中,我有1個固定位置的經度 - 緯度。現在,使用iPhone設備的用戶可以在任何地方移動,甚至他可以旋轉他的設備,箭頭(某些uiimageview)應該指向該修復位置,以便用戶每次都可以獲取指向該位置的路線。我嘗試如下。如何將方向箭頭旋轉到特定位置
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D here = newLocation.coordinate;
[self calculateUserAngle:here];
}
-(void) calculateUserAngle:(CLLocationCoordinate2D)user {
NSLog(@"my destination is %f ; %f", fixlocLat, fixlocLon);
degrees = degrees + atan2(sin(fixlocLon-user.longitude)*cos(fixlocLat),cos(user.latitude)*sin(fixlocLat) - sin(user.latitude)*cos(fixlocLat)*cos(fixlocLon-user.longitude));
//get angle between user location and fix location
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
arrow.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI/180);
}
,但上面的代碼將永遠旋轉箭頭約。每個位置向北2-3度。
我的問題與this Stack Overflow question類似,但使用此鏈接中的代碼我得到錯誤的方向。 請幫助我。
以及使用加速度計或gyrodata的任何想法對我都有幫助。
thanx提前。
位置有多遠?如果距離很遠,則可能需要[大圓距離](http://en.wikipedia.org/wiki/Great-circle_distance)計算。 – RabinDev
我們如何使用xcode(物鏡c)中的大圓距離計算和距離可以遠遠大約。千公里。 – Dhawal
距離是可變的,它會隨着用戶移動而更新,但範圍大約在0到1000km之間。 – Dhawal