0

我想在用户跟随的旋转的谷歌地图上显示自行车/汽车图像。怎么可能。我添加didUpdateToLocation了更新用户位置的方法,并添加viewForAnnotation了显示自行车当前位置的方法。但无法在用户关注的地图上显示自行车。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocation *currentLocation = newLocation;
    if(currentLocation != nil)
    {
        CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
         MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"India" subTitle:@"Sarvopari Mall"];
        [self.myMapView addAnnotation:annotation];
    }
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView
            viewForAnnotation:(id <MKAnnotation>)annotation{

    MKAnnotationView *result = nil;

    if ([annotation isKindOfClass:[MyAnnotation class]] == NO)
    {
        return result;
    }

    if ([mapView isEqual:self.myMapView] == NO)
    {
        return result;
    }

    MyAnnotation *senderAnnotation = (MyAnnotation *)annotation;

    NSString *pinReusableIdentifier =
    [MyAnnotation
     reusableIdentifierforPinColor:senderAnnotation.pinColor];


    MKAnnotationView *annotationView = (MKAnnotationView *)
    [mapView
     dequeueReusableAnnotationViewWithIdentifier:
     pinReusableIdentifier];

    if (annotationView == nil){
        annotationView =
        [[MKAnnotationView alloc]  initWithAnnotation:senderAnnotation
                                      reuseIdentifier:pinReusableIdentifier];

        annotationView.canShowCallout = YES;

    }

    UIImage *pinImage = [UIImage imageNamed:@"Bike.png"];
    if (pinImage != nil){
        annotationView.image = pinImage;
        annotationView.canShowCallout = YES;
    }

    result = annotationView;

    return result;
}
4

1 回答 1

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

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

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

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

    return annotationView;
}
于 2013-09-04T07:34:56.463 回答