2014-12-07 2 views
1

iOS 응용 프로그램의지도에 주석을 표시하는 데 문제가 있습니다.MapKit 주석이 표시되지 않습니다.

설명서의 규칙을 준수했습니다. 디버깅에서 viewForAnnotation이 주석 포인트에 대해 호출 된 적이없는 것 같습니다.

뷰 컨트롤러의 코드는 다음과 같습니다

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super 
    // Do any additional setup after loading the view, typically from a nib. 

    self.mapView.delegate = self; 
    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 

    [self.locationManager requestAlwaysAuthorization]; 

    [self.locationManager startUpdatingLocation]; 

    self.mapView.showsUserLocation = YES; 
    [self.mapView setMapType:MKMapTypeStandard]; 
    [self.mapView setZoomEnabled:YES]; 
    [self.mapView setScrollEnabled:YES]; 

    self.locationManager.distanceFilter = kCLDistanceFilterNone; 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    [self.locationManager startUpdatingLocation]; 


    //View Area 
    MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } }; 
    region.center.latitude = self.locationManager.location.coordinate.latitude; 
    region.center.longitude = self.locationManager.location.coordinate.longitude; 
    region.span.longitudeDelta = 0.005f; 
    region.span.longitudeDelta = 0.005f; 
    [self.mapView setRegion:region animated:YES]; 


    [self.mapView addAnnotations:[self createAnnotations]]; 
} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:YES]; 

} 

- (void)didReceiveMemoryWarning {  
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
    { 
     NSLog(@"viewForAnnotation"); 

     if([annotation isKindOfClass:[MKUserLocation class]]) { 
      return nil; 
     } 

     MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] init]; 

     pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"foo"]; 

     [pinView setPinColor:MKPinAnnotationColorGreen]; 
     pinView.animatesDrop = YES; 
     pinView.canShowCallout = YES; 

     return pinView; 
} 

- (NSMutableArray *)createAnnotations 
{ 
    NSMutableArray *annotations = [[NSMutableArray alloc] init]; 
    CLLocationCoordinate2D coord; 
    coord.latitude = 37.4; 
    coord.longitude = -122.2; 
    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
    [annotations addObject:annotation]; 
    return annotations; 
} 

@end 

답변

0

하나의 명백한 문제는 createAnnotations 방법 여기에 있습니다 :

CLLocationCoordinate2D coord; 
coord.latitude = 37.4; 
coord.longitude = -122.2; 
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
[annotations addObject:annotation]; 


annotationcoordinate 속성이 설정되지 않습니다. annotation을 만든 후

설정을 : 그-문제에 대한

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
annotation.coordinate = coord; // <-- add this line 
[annotations addObject:annotation]; 
+0

덕분에 그 viewForAnnotation 여전히 사용자 만 포인트 요구되고 있음을 아직도있다. –

관련 문제