如何在地图视图中显示引脚注释?

发布于 2024-10-24 22:56:57 字数 1976 浏览 0 评论 0原文

我有一个带有该部分的表格视图,在第四部分中,我插入了地图视图。现在我想在单击图钉时显示当前的纬度和经度。我有纬度和经度。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉溺在你眼里的海 2024-10-31 22:56:57

您是否正确设置了标注?

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

Have you set the callout correct?

MKPinAnnotationView *annotationView = nil; 
---init of view etc.. 
annotationView.canShowCallout = YES;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文