我正在尝试根据用户位置标题方向转换注释视图。注释视图没有正确更改。
LocationMapView.userTrackingMode=YES;
locationManager.headingFilter =5;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
(void) calculateUserAngle:(CLLocationCoordinate2D)current {
double x = 0, y = 0 , deg = 0,delLon = 0;
float fixLon=current.longitude;
float fixLat=current.latitude;
delLon = fixLon - current.longitude;
y = sin(delLon) * cos(fixLat);
x = cos(current.latitude) * sin(fixLat) - sin(current.latitude) * cos(fixLat) * cos(delLon);
deg = RADIANS_TO_DEGREES(atan2(y, x));
if(deg<0){
deg = -deg;
} else {
deg = 360 - deg;
}
degrees = deg;
}
(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
newLocation = [locations lastObject];
NSLog(@"DidUpdateLocation--%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
CLLocationCoordinate2D here = newLocation.coordinate;
[self calculateUserAngle:here];
}
(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
annotationView.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI / 180);
}