В моем приложении у меня есть широта-долгота в 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 градуса север для каждого места.
Мой вопрос похож на этот вопрос. но используя код из этой ссылки, я получаю неправильное направление. пожалуйста, помогите мне в этом.
а также если какая-либо идея с использованием акселерометра или гиродата будет полезна для меня.
thanx заранее.