gpt4 book ai didi

iphone - 如何在 map View 中放置图钉?

转载 作者:行者123 更新时间:2023-12-03 19:13:02 24 4
gpt4 key购买 nike

我是 iPhone 应用程序的新用户。我想在我的 MKMapView 中显示图钉。我该怎么做?

给我一​​些宝贵的建议。

最佳答案

您需要创建一个实现MKAnnotation协议(protocol)的委托(delegate):

@interface AnnotationDelegate : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id) initWithCoordinate:(CLLocationCoordinate2D)coord;

@end

@implementation AnnotationDelegate

@synthesize coordinate;

- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
coordinate.latitude = coord.latitude;
coordinate.longitude = coord.longitude;
return self;
}

@end

对于每个 map 点,您需要实例化一个 AnnotionDelegate 对象(传入该点的坐标)并将其添加到 MKMapView: p>

AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] initWithCoordinate:coordinate] autorelease];
[self._mapView addAnnotation:annotationDelegate];

关于iphone - 如何在 map View 中放置图钉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1806770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com