我对 XCode 和 Objective-c 很陌生。这个问题之前可能已经回答过,但我无法让它发挥作用。我的目标是在谷歌地图上显示多个注释。我有一堆 Lats 和 Longs,但是到目前为止,我只能显示一个注释。如何一次显示所有注释。我有下面的代码MKMapView
-
- (void)viewDidLoad {
// Set some coordinates for our position
CLLocationCoordinate2D location;
location.latitude = (double) 44.271745;
location.longitude = (double) -88.453265;
// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Appleton" andCoordinate:location];
[self.mapview addAnnotation:newAnnotation];
[newAnnotation release];
self.mapview.region = MKCoordinateRegionMakeWithDistance(location,100000,100000);
}
我知道我可以循环并实例化newAnnotation
,然后用于addAnnotation
添加注释。但我不知道该怎么做。这可能是非常基本的,但我对此很陌生。任何帮助将不胜感激。
//
// 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 {
[super init];
title = ttl;
coordinate = c2d;
return self;
}
- (void)dealloc {
[title release];
[super dealloc];
}
@end