2012-05-23 2 views
2

여러 개의 주석이있는지도를 만들고 있는데 어떻게 동적으로 (CoreData에 포함 시켰는지) 알지 못합니다.지도 주석을 동적으로 배치하는 방법은 무엇입니까?

- (void)viewDidLoad { 
    [super viewDidLoad]; 


    CLLocation *userLoc = mapView.userLocation.location; 
    CLLocationCoordinate2D userCoordinate = userLoc.coordinate; 

    NSLog(@"user latitude = %f",userCoordinate.latitude); 
    NSLog(@"user longitude = %f",userCoordinate.longitude); 

    mapView.delegate=self; 

    NSMutableArray* annotations=[[NSMutableArray alloc] init]; 




    CLLocationCoordinate2D theCoordinate1; 
    theCoordinate1.latitude = 43.82078; 
    theCoordinate1.longitude = 15.307265; 

    CLLocationCoordinate2D theCoordinate2; 
    theCoordinate2.latitude = 44.91035917; 
    theCoordinate2.longitude = 14.65576172; 



    MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init]; 

    myAnnotation1.coordinate=theCoordinate1; 
    [email protected]"Rohan"; 
    [email protected]"in the city"; 

    MyAnnotation* myAnnotation2=[[MyAnnotation alloc] init]; 

    myAnnotation2.coordinate=theCoordinate2; 
    [email protected]"Vaibhav"; 
    [email protected]"on a Bridge"; 



    [mapView addAnnotation:myAnnotation1]; 
    [mapView addAnnotation:myAnnotation2]; 


    [annotations addObject:myAnnotation1]; 
    [annotations addObject:myAnnotation2]; 


    NSLog(@"%d",[annotations count]); 
    //[self gotoLocation];//to catch perticular area on screen 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 

    // Walk the list of overlays and annotations and create a MKMapRect that 
    // bounds all of them and store it into flyTo. 
    MKMapRect flyTo = MKMapRectNull; 
    for (id <MKAnnotation> annotation in annotations) { 
     NSLog(@"fly to on"); 
     MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); 
     MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); 
     if (MKMapRectIsNull(flyTo)) { 
      flyTo = pointRect; 
     } else { 
      flyTo = MKMapRectUnion(flyTo, pointRect); 
      //NSLog(@"else-%@",annotationPoint.x); 
     } 
    } 


    // Position the map so that all overlays and annotations are visible on screen. 
    mapView.visibleMapRect = flyTo; 


    UIBarButtonItem* temp=[[UIBarButtonItem alloc] init]; 
    [email protected]"Back"; 
    self.navigationItem.backBarButtonItem=temp; 
    //[temp release]; 
} 

추신 :

나는 그들이 코드로 고정 퍼 팅 해요 추가 코드가 필요하면 알려주십시오.

감사의 도움을

UPDATE :

Locations.h

... 
@interface Locations : NSManagedObject 

@property (nonatomic, retain) NSDecimalNumber * lat; 
@property (nonatomic, retain) NSDecimalNumber * lon; 
... 

업데이트 2 : 여기

내가 주석을 퍼 팅있어 예제 코드입니다 "결정된".

http://dl.dropbox.com/u/77033905/stackoverflow/Map.zip

어떻게 배열을 통해이 주석을 추가 할 수 있습니까? (배열의 좌표, 제목, subitle 및지도에 추가합니다.)이 위치를 정의

+0

동적으로 무엇을 의미합니까? –

+0

PHP에서 나는 이것들을 다음과 같이 두었습니다 : $ array [] = $ annotation; 등 – CroiOS

+0

아직도 모른다. 네가 정확히하고 싶은 걸 내버려 둬. –

답변

0

위치 인스턴스가 어노테이션 될 것입니다 단지 할

[mapView addAnnotations:locationArray]; 

Location.h

... 
@interface Locations : NSManagedObject <MKAnnotation>{ 
    CLLocationCoordinate2D coordinate; 
} 

@property (nonatomic, retain) NSDecimalNumber * lat; 
@property (nonatomic, retain) NSDecimalNumber * lon; 
... 

위치 .m

... 
- (CLLocationCoordinate2D)coordinate 
{ 
coordinate.latitude = [self.lat doubleValue]; 
coordinate.longitude = [self.lon doubleValue]; 
return coordinate; 
} 

- (NSString *)title 
{ 
return @"yourTitle"; 
} 

- (NSString *)subtitle 
{ 
return @"yourSubtitle"; 
} 

원하는 것이 맞습니까?

+0

죄송합니다, 아니요. 첫 번째 게시물에서 코드 위에 주석을 추가하고 싶습니다. 나는 첫 번째 게시물을 업데이트했다. – CroiOS

+0

나는 자야 해. 오전 4시입니다. –

+0

여기에 22:00입니다. – CroiOS

관련 문제