繁体   English   中英

MapKit引脚标题未显示

[英]MapKit pin title not showing

该位置正在运行,但标题未显示,最奇怪。

location.latitude = (double) 51.501468;
location.longitude = (double) -0.141596;

// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"ABC" andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
// [newAnnotation release];

MapViewAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {

NSString *title;
CLLocationCoordinate2D coordinate;

}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;

@end

和MapViewAnnotation.m

 #import "MapViewAnnotation.h"

 @implementation MapViewAnnotation

 @synthesize title, coordinate;

 - (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
title = ttl;
coordinate = c2d;
return self;
 }

 @end

[newAnnotation版本]已删除,以使ARC保持满意:-)有什么想法吗?

这达到了目的:

[mapView selectAnnotation:newAnnotation animated:YES];

以前,仅当您单击图钉时,标题才会显示。

您致电注释代表, 请参考此链接mapkit-example-in-iphone

该代码看起来不错(除了init方法的非标准实现之外)。

标题(标注)未出现的最可能原因是,在您的viewForAnnotation委托方法中,您没有将canShowCallout设置为YES (默认为NO )。

viewForAnnotation委托方法中,创建MKAnnotationView ,将canShowCallout设置为YES


未显示标题/标注无关MapViewAnnotation类中的init方法应按以下方式实现:

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
    self = [super init];
    if (self) {
        title = ttl;
        coordinate = c2d;
    }
    return self;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM