我有一个桌面视图和第四节,我插入了mapview.Now我想显示点击pin的当前纬度和经度。我有纬度和经度。 Pin正出现在mapview上,但当我点击它时,我没有得到任何东西。我写的代码在下面。任何人都可以告诉我,这里的问题是什么?任何示例代码或教程?
//这是获取位置坐标的文件
#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
在插入地图的文件中
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];
}
谢谢!
答案 0 :(得分:0)
您是否正确设置了标注?
MKPinAnnotationView *annotationView = nil;
---init of view etc..
annotationView.canShowCallout = YES;