根据用户的方向在地图中跟随旋转图像

时间:2013-09-04 13:05:17

标签: iphone ios google-maps mkmapview mapkit

我想在用户跟随的方向旋转自行车/汽车图像。现在图像遵循方向,但看起来不指令,我们可以说点不遵循方向:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"Bike.png"];
    annotationView.annotation = annotation;

    return annotationView;
}

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

    currentLocation = newLocation;
    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];
    }
}

1 个答案:

答案 0 :(得分:1)

查看核心位置-[CLLocationManagerDelegate locationManager:didUpdateHeading:]