[英]how to display pin annotations in mapview?
我在該部分有一個tableview,在第四部分中插入了mapview。現在我想在單擊圖釘時顯示當前的緯度和經度。我有緯度和經度。 大頭針出現在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];
}
謝謝!
標注正確嗎?
MKPinAnnotationView *annotationView = nil;
---init of view etc..
annotationView.canShowCallout = YES;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.