0

这是我第一次在 Objective C 中为 IOS 编程,所以请多多包涵。

基本上,我的 CLLocationCoordinate2D 值在传递对象后会自行更改。

首先,此方法应模拟数据库

/* *
 * Static getMarkers
 * Returns an NSMutableArray of CustomMarkers
 * */
+ (NSMutableArray*) getMarkers
{
    NSMutableArray * markers = [[NSMutableArray alloc] init];


    CLLocationCoordinate2D projection = CLLocationCoordinate2DMake(50.850282, 4.351932);
    CustomMarker *m = [[CustomMarker alloc] initWithTEN:@"Brussels"
                                                TFR:@"Bruxelles Centre"
                                                TNL:@"Brussel Centrum"
                                           Position:&projection
                                           Filename:@"FILE.TXT"
                                         MarkerType:Verhaal];
    [markers addObject:m];

    return markers;
}

当我在这些行上设置断点时,一切都完美无缺。

然后,当我尝试在视图控制器的循环中使用标记时,它变得很难看。

// Load markers from datahelper
NSMutableArray * markers = [DataHelper getMarkers];


// Put the loaded markers on the map
for (CustomMarker *lm in markers) {

在这里,一旦从 datahelper 接收到标记,位置就出错了。

我遇到的另一个问题是枚举 MarkerType 从一开始就为零。

谢谢您的帮助!

4

2 回答 2

1

你的参数不应该是(CLLocationCoordinate2D*)position,应该是(CLLocationCoordinate2D)position。然后你可以停止传递指针。

您的问题更有可能出现在gmsm.position = *(lm.Position);(*lm.Position).latitude, (*lm.Position).longitude. 基本上,停止使用指向位置结构的指针,因为你把事情弄混了并访问了错误的内存位置(看起来像取消引用指向CustomMarker实例的有效指针)。

于 2013-10-29T13:31:05.000 回答
0

如果您将投影传递为&projection,则通常意味着initWithTEN...传递给它的方法可能出于某种原因想要更改投影。检查文档,或者如果您有来源,请签入该方法。

于 2013-10-29T13:28:21.610 回答