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

2 回答 2

2

您已为 NUH、NUHER 和 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
于 2013-08-30T03:04:03.687 回答
0

这可能是因为您不断重新分配相同的 myAnn 变量。您应该尝试创建多个Annotations,如果需要,将它们称为 myAnn1、myAnn2。

稍后,如果你有超过 3 个这样的东西,你应该考虑制作一个集合并循环遍历它,而不是一个接一个地创建它们

于 2013-08-30T02:39:13.920 回答