如何在地图视图中显示引脚注释?
我有一个带有该部分的表格视图,在第四部分中,我插入了地图视图。现在我想在单击图钉时显示当前的纬度和经度。我有纬度和经度。 Pin 出现在地图视图上,但是当我单击它时,我没有得到任何内容。我编写的代码如下。有人能告诉我,这里有什么问题吗?有相关的示例代码或教程吗?
获取位置坐标的文件
#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];
}
谢谢!
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, i m 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正确设置了标注?
Have you set the callout correct?