简体   繁体   中英

how to display pin annotations in mapview?

I have one tableview with the section and in fourth section, i have inserted mapview.Now i want to display current latitude and longitude on clicking the pin.I have latitude and longitude. Pin is appearing on mapview but when i am clicking it, im not getting anything.Code i have written is below.Can anyone tell that, whats the problem here? Any sample code or tutorial for that?

//This is file to get location coordinates

#import "VolunteerDetailAnnotation.h"

@implementation VolunteerDetailAnnotation
@synthesize title;
@synthesize subtitle;
@synthesize coordinate;

/*-(id)init
{
    self=[super init];
    if(!self)
    {
        return nil; 
    }
    self.title=nil;
    self.subtitle=nil;
    return self;
}*/

-(NSString *)gettitle
{
    return title;

}
-(NSString *)getsubtitle
{
    return subtitle;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D)inCoord{
    self = [self init];
    self.coordinate = inCoord;
    return self;
}


- (void)dealloc
{
    self.title=nil;
    self.subtitle=nil;
    [super dealloc];
}
@end

In the file where map is inserted

if(index.section==3)
{
            mapView=[[MKMapView alloc] initWithFrame:frame22];
            mapView.mapType=MKMapTypeStandard;
            CLLocationCoordinate2D location = mapView.userLocation.coordinate;
            MKCoordinateSpan span;

            MKCoordinateRegion region;

            location.latitude  = [[aVolunteer latitude] floatValue];
            location.longitude = [[aVolunteer longitude] floatValue];
            mapView.scrollEnabled=YES;
            span.latitudeDelta = 0.05;
            span.longitudeDelta = 0.05;
            mapView.showsUserLocation=YES;
            region.span = span;
            region.center = location;
            VolunteerDetailAnnotation *placemark=[[VolunteerDetailAnnotation alloc] initWithCoordinate:location];
            placemark.title=@"Current Location";
            placemark.subtitle=[NSString stringWithFormat:@"%@: %@",aVolunteer.latitude,aVolunteer.longitude] ;
            [mapView addAnnotation:placemark];
            [mapView setRegion:region animated:YES];
            [mapView regionThatFits:region];
            [cell1 addSubview:mapView];
}

Thanks!

Have you set the callout correct?

MKPinAnnotationView *annotationView = nil; 
---init of view etc.. 
annotationView.canShowCallout = YES;

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