2013-08-29 39 views
1

我加入註解註冊並有應該是在我的地圖5個註釋針腳,但只有2個出現,顯示此錯誤:實例被釋放,而鍵值觀察家仍用它

的類Annotation的實例0x9d8e720被解除分配,而值爲 的值觀察者仍在其中註冊。觀察信息是 泄漏,甚至可能被誤認爲是其他物體。 坐落在NSKVODeallocateBreak斷點停止^ h

//NUH COORDINATES 
#define NUH_latitude 1.293700; 
#define NUH_longitude 103.783353; 

//span 
#define the_span 0.002f; 

//NHGP COORDINATES! 
#define NHGP_latitude 1.295938; 
#define NHGP_longitude 103.782857; 

//NUHER COORDINATES 
#define NUHER_latitude 1.294968; 
#define NUHER_longitude 103.783716; 

//NUCIS COORDINATES 
#define NUCIS_latitude 1.293149; 
#define NUCIS_longitude 103.783464; 

//Viva-UCCC COORDINATES! 
#define VivaUCCC_latitude 1.294099; 
#define VivaUCCC_longitude 103.783233; 

//span 
MKCoordinateSpan span; 
span.latitudeDelta = the_span; 
span.longitudeDelta = the_span; 
MKCoordinateRegion myRegion; 

//center 
CLLocationCoordinate2D center; 
center.latitude = NUH_latitude; 
center.longitude = NUH_longitude; 
myRegion.center =center; 
myRegion.span = span; 
[mapview setRegion:myRegion animated:YES]; 

//annotation 
NSMutableArray * locations = [[NSMutableArray alloc] init]; 
CLLocationCoordinate2D location; 
Annotation * myAnn; 

//NUH location 
myAnn = [[Annotation alloc] init]; 
location.latitude = NUH_longitude; 
location.longitude = NUH_longitude; 
myAnn.coordinate = location; 
myAnn.title = @"NUH"; 
[locations addObject:myAnn]; 

//NHGP location 
myAnn = [[Annotation alloc] init]; 
location.latitude = NHGP_latitude; 
location.longitude = NHGP_longitude; 
myAnn.coordinate = location; 
myAnn.title = @"National Healthcare Group Polyclinic "; 
[locations addObject:myAnn]; 

//NUHER location 
myAnn = [[Annotation alloc] init]; 
location.latitude = NUHER_longitude; 
location.longitude = NUHER_longitude; 
myAnn.coordinate = location; 
myAnn.title = @"National University Hospital Emergency Room"; 
[locations addObject:myAnn]; 

//NUCIS location 
myAnn = [[Annotation alloc] init]; 
location.latitude = NUCIS_longitude; 
location.longitude = NUCIS_longitude; 
myAnn.coordinate = location; 
myAnn.title = @"National University Cancer Institute Singapore"; 
[locations addObject:myAnn]; 

//Viva-UCCC location 
myAnn = [[Annotation alloc] init]; 
location.latitude = VivaUCCC_latitude; 
location.longitude = VivaUCCC_longitude; 
myAnn.coordinate = location; 
myAnn.title = @"Viva-University Children's Cancer Centre"; 
[locations addObject:myAnn]; 

[self.mapview addAnnotations:locations]; 
+0

這個錯誤通常發生在座標無效時。確保緯度從-90到+90,經度從-180到+180。請參閱http://stackoverflow.com/questions/5872547/warning-in-custom-map-annotations-iphone?lq=1。 – Anna

+0

我從谷歌地圖得到座標,緯度是從-90到+90,經度是從-180到+180的所有我的註釋引腳。但仍然無法讓我的所有引腳工作。 @AnnaKarenina – user2621090

+0

顯示添加註釋的代碼(編輯您的問題並添加代碼)以及如何設置座標屬性。 – Anna

回答

2

你指定的經度,和NUCIS。他們不會出現在你想要的地方(這就是爲什麼你只看到2),我認爲這個錯誤是因爲這些值對緯度無效。

//NUH location 
location.latitude = NUH_longitude; // <-- should be NUH_latitude 
... 
//NUHER location 
location.latitude = NUHER_longitude; // <-- should be NUHER_latitude 
... 
//NUCIS location 
location.latitude = NUCIS_longitude; // <-- should be NUCIS_latitude 
+0

非常感謝! @zpasternack – user2621090

0

這可能是因爲你保持reallocting相同myAnn變量。您應該嘗試創建多個Annotation s,如果必須,請將它們稱爲myAnn1,myAnn2。

後來,如果你有3個以上的這些事情,你應該考慮的集合,並通過它的循環,而不是爲他們創造的緯度爲國大醫院,NUHER一個接一個

相關問題