2013-03-01 40 views
0

嗨我的數組充滿了三個對象,並且只有1個註釋顯示在地圖上。有任何想法嗎?如果我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

[MapView的addAnnotations:新]。保持這個循環 – Murali 2013-03-01 05:28:06

+0

什麼是你的地圖縮放級別...看你的座標是否在區域內或者...檢查你的循環..在添加註釋之前它的支架已經結束 – Nit 2013-03-01 05:28:44

+0

@Murali我將它移動到for循環中,和同樣的問題。 – Cliffordwh 2013-03-01 05:30:45

回答

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]; 
}