0

我想在用户移动的方向上显示自定义汽车/自行车图像,现在的问题是,自行车朝着用户移动的方向前进,但是当用户倒车时,它也以倒车模式显示。

下面是代码:

- (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"];
    annotationView.transform = CGAffineTransformMakeRotation(45);
    return annotationView;

}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (newLocation.horizontalAccuracy < 0)
        return;
    if  (!newLocation)
        return;


    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];
    }
}
4

0 回答 0