2013-08-29 85 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一个接一个

相关问题