[英]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. 我在该部分有一个tableview,在第四部分中插入了mapview。现在我想在单击图钉时显示当前的纬度和经度。我有纬度和经度。 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? 大头针出现在mapview上,但是当我单击它时,我什么也没收到。我写的代码在下面。任何人都可以告诉我,这是什么问题? 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.