简体   繁体   中英

Logic Issue - MapKit

Following is my MapKitDisplayViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
        region.center.latitude = 22.569722 ;
        region.center.longitude = 88.369722;
        [mapView setRegion:region animated:YES]; 

        [mapView setDelegate:self];

        DisplayMap *ann = [[DisplayMap alloc] init]; 
        ann.title = [person name];
        ann.subtitle = [person address]; 
        ann.person = person;

        ann.coordinate = region.center; 
        [mapView addAnnotation:ann];
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
 (id <MKAnnotation>)annotation {
        MKPinAnnotationView *pinView = nil; 
        if(annotation != mapView.userLocation) 
        {
                static NSString *defaultPinID = @"com.invasivecode.pin";
                pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
                if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                                                                  initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
                UIImageView *iconView = [[UIImageView alloc] initWithImage: [UIImage imageWithString:@?????????????????];
                annotationView.leftCalloutAccessoryView = iconView;

                pinView.pinColor = MKPinAnnotationColorRed; 
                pinView.canShowCallout = YES;
                pinView.animatesDrop = YES;
                } 

        return pinView;
}

You will see the line where it'll say ???????? I need to display an image there.

When the user clicks a pin point, then the popup will appear. Title, subtitle and the image is suppose to be displayed on the popup. I believe that the following line should display the image for that popup. But i am unable to pass the Person object's (or the pipoint which contains the person object) image URL to this method. Can you help me display the selected Image URL here.

It doesn't fail. I need to know how to pass the person object selected by the user to viewForAnnotation method

Ahhh, I see know. I had a similar issue, and it can be a be tricky. I'm right in the middle of reworking my Annotation code, so you can see it since it doesn't work, but I you need to store something away that you can then later retrieve.

I made an object, MKAnnotation.

@interface FotoMapLocation : NSObject <MKAnnotation> {

So when I make an annotation, I create a FotoMapLocation object.

    FotoMapLocation *annotation = [[FotoMapLocation alloc] initWithTitle:title 
                                                            subtitle:subtitle 
                                                                foto:aFoto 
                                                      thumbnailImage:aFoto.thumbnailImage
                               ];
    [mapView addAnnotation:annotation]; 

Now, you can store anything here. So store your Person object in your subclass.

I know this is only halfway there, and very rambling. But I was right in the middle of ripping that code out, and then another fire came up, so it is currently in an in-between state. But I expect to return to it in a few days. I'll check back and if you don't have anything I'll update this answer.

This is what i did, in the viewForAnnotation method

DisplayMap *dm= (DisplayMap *)annotation;

NSString *url = [dm.person urlOfPerson];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM