2013-03-01 2 views
0

안녕하세요. 내 배열은 세 개의 개체로 채워져 있으며지도에는 단 한 개의 주석 만 표시됩니다. 어떤 아이디어? NSLog 특정 요소가 채워지면 표시 할 3 개의 주석을 가져 오지 마십시오.한 주석 만 표시

NSMutableArray *currentBranch = [xmlParser branch]; 
int counter=[currentBranch count]; 

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

CLLocationCoordinate2D coordinates; 
Mapdets * myAnn; 
myAnn = [[Mapdets alloc] init]; 

[mapview setMapType:MKMapTypeStandard]; 
[mapview setZoomEnabled:YES]; 
[mapview setScrollEnabled:YES]; 

MKCoordinateRegion region = {{0.0, 0.0}, {0.0,0.0 }}; 
region.center.latitude = -33.86434888; 
region.center.longitude = 151.2090236; 
region.span.longitudeDelta = 55.80f; 
region.span.latitudeDelta = 55.80f; 
[mapview setRegion:region animated:YES]; 


for(int i=0;i<counter;i++) 

{ 
Mapdets *currentBranch = [[xmlParser branch] objectAtIndex:i]; 




NSString *title = currentBranch.title; 
NSString *subtitle = currentBranch.subtitle; 
NSString *lat = currentBranch.lat; 
NSString *lng = currentBranch.lng;  


coordinates.latitude = [lat doubleValue]; 
coordinates.longitude = [lng doubleValue]; 

    myAnn.coordinate = coordinates; 
    myAnn.title = title; 
    myAnn.subtitle = subtitle; 

NSLog(@"%@", title); 

[new addObject:myAnn]; 
} 

[mapview addAnnotations:new]; 

도움 주셔서 감사합니다!

+0

[지도보기 addAnnotations : 신품; 이것을 for 루프에 유지하십시오 – Murali

+0

지도 확대/축소 레벨 ... 좌표가 영역 내에 있는지 확인하십시오 ... for 루프를 확인하십시오. 주석이 추가되기 전에 해당 브래킷이 끝났습니다 – Nit

+0

@Murali for 루프로 이동했습니다. , 그리고 같은 문제. – Cliffordwh

답변

1

.. 다만 루프에 myAnn를 초기화

for(int i=0;i<counter;i++) 
{ 
    Mapdets * myAnn; 
    myAnn = [[Mapdets alloc] init]; 
    Mapdets *currentBranch = [[xmlParser branch] objectAtIndex:i]; 
    NSString *title = currentBranch.title; 
    NSString *subtitle = currentBranch.subtitle; 
    NSString *lat = currentBranch.lat; 
    NSString *lng = currentBranch.lng;  

    coordinates.latitude = [lat doubleValue]; 
    coordinates.longitude = [lng doubleValue]; 

    myAnn.coordinate = coordinates; 
    myAnn.title = title; 
    myAnn.subtitle = subtitle; 

    NSLog(@"%@", title); 
    [new addObject:myAnn]; 
}