2012-04-25 19 views
0

マップビューに注釈を追加しようとしていますが、追加できません。誰かが私が間違っていることを私に示唆することはできますかコード:マップを追加するコード:(mapview.annotationsのIDアノテーション){ [のMapViewのremoveAnnotation:注釈]を
:別の方法で注釈を追加iPhoneのマップにカスタム注釈を表示できません

mapview = [[MKMapView alloc] initWithFrame:CGRectMake(10, 175, 300, 268)]; 
mapview.delegate = self; 
mapview.userInteractionEnabled = TRUE; 
[mapview setZoomEnabled:TRUE]; 
[mapview setScrollEnabled:TRUE]; 
mapview.showsUserLocation = TRUE; 
[self.view addSubview:mapview]; 

//。 }

 for(int i =0;i<arrEventList.count;i++){ 
      CLLocationCoordinate2D theCoordinate; 
      theCoordinate.latitude = [[NSString stringWithFormat:@"%@",[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:@"lat"]] floatValue]; 
      theCoordinate.longitude = [[NSString stringWithFormat:@"%@",[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:@"lng"]] floatValue]; 

      MyLocation *annotation = [[[MyLocation alloc] initWithName:[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:@"event"] address:[(NSDictionary*)[arrEventList objectAtIndex:i] objectForKey:@"place"] coordinate:theCoordinate] autorelease]; 
      [mapview addAnnotation:annotation]; 
      //[annotations addObject:myAnno.annotation]; 
     } 

//デリゲートメソッド:デリゲートメソッドの上

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation { 
static NSString *identifier = @"MyLocation"; 
if ([annotation isKindOfClass:[MyLocation class]]) { 

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    } else { 
     annotationView.annotation = annotation; 
    } 

    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 
    annotationView.image=[UIImage imageNamed:@"annotation.png"];//here we use a nice image instead of the default pins 

    return annotationView; 
} 

return nil; 

}

だけ自己位置のために呼ばれていますが、私が追加したい他の注釈のために呼び出されません。

誰かが、私は問題を発見した私の過ち

@interface MyLocation : NSObject <MKAnnotation> { 
NSString *_name; 
NSString *_address; 
CLLocationCoordinate2D _coordinate; 

}

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

- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate; 

@end 
//Mylocation class: 

@implementation MyLocation 
@synthesize name = _name; 
@synthesize address = _address; 
@synthesize coordinate = _coordinate; 

- (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate { 
if ((self = [super init])) { 
    _name = [name copy]; 
    _address = [address copy]; 
    _coordinate = coordinate; 
    } 
    return self; 
} 

- (NSString *)title { 
if ([_name isKindOfClass:[NSNull class]]) 
    return @"Unknown charge"; 
else 
    return _name; 
} 

- (NSString *)subtitle { 
return _address; 
} 

答えて

0

に私を指すことができます。私のコードは正しいです。 latittudeと経度の値は、どのように交換されました。私の間違いですが、私は今修正しました

関連する問題