我正在开发一个简单的地图,我想使用例如公司名称在地图上找到一家公司。例如,“苹果公司”。
你知道我该怎么做吗?
非常感谢!
问候,雅舒
您需要有一个实现 MKAnnotation 协议的类。这是一个例子
@interface MapPin : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *subtitle;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description;
@end
这是实现:
@implementation MapPin
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:placeName description:description {
self = [super init];
if (self != nil) {
coordinate = location;
title = placeName;
[title retain];
subtitle = description;
[subtitle retain];
}
return self;
}
- (void)dealloc {
[title release];
[subtitle release];
[super dealloc];
}
@end
然后,在您的 MapView 中,您需要添加您的公司位置,如下所示。
CLLocationCoordinate2D coord = [[[CLLocation alloc] initWithLatitude:35.936902 longitude:-79.024953] coordinate];//Here you need to mention your company latitude and longitude
MapPin *pin = [[MapPin alloc] initWithCoordinates:coord placeName:@"Apple Inc" description:@""];
[map addAnnotation:pin];
希望这会有所帮助....