0
나침반 메서드를 통해 이동하는 방향으로 자전거/자동차를 이동하고 싶습니다. 왜냐하면, 나는 didUpdateHeading 메서드를 사용했지만 여전히 사용자의 방향으로 자전거 이미지를 이동할 수 없습니다.CLLocationManagerDelegate 클래스의 나침반 메서드를 통해 사용자가 이동하는 방향으로 이미지 회전
<pre>
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"Bike.png"];
return annotationView;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
currentLocation = newLocation;
previousLocation = oldLocation;
if(currentLocation != nil)
{
if (myAnnotation)
{
[self.myMapView removeAnnotation:myAnnotation];
}
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
myAnnotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"Current Location" subTitle:nil];
[self.myMapView addAnnotation:myAnnotation];
}
}
- (void)locationManager:(CLLocationManager*)manager didUpdateHeading:(CLHeading*)newHeading {
if (newHeading.headingAccuracy > 0) {
float heading = -1.0f * M_PI * newHeading.magneticHeading/180.0f;
annotationView.transform = CGAffineTransformMakeRotation(heading);
}
}
</pre>