简体   繁体   English

CLLocationCoordinate2D传递后获取奇怪的值

[英]CLLocationCoordinate2D gets weird values after being passed

It's my first time programming for IOS in objective C, so please bear with me. 这是我第一次在目标C中为IOS编程,请耐心等待。

Basically, my values of my CLLocationCoordinate2D change by themselves after passing the objects. 基本上,传递对象后,我的CLLocationCoordinate2D值会自行更改。

To start off, this method should simulate a database 首先,此方法应模拟一个数据库

/* *
 * 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;
}

When I put a breakpoint on these lines, everything is perfect and right. 当我在这些行上设置断点时,一切都完美无缺。

Then as I try to use the markers in a loop in the view controller, it gets ugly. 然后,当我尝试在视图控制器的循环中使用标记时,它变得很丑陋。

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


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

Here, as soon as the markers are received from the datahelper, the position is wrong. 在这里,一旦从datahelper接收到标记,位置就会错误。

Another issue I'm having is that the enum MarkerType is nil from the very beginning. 我遇到的另一个问题是,枚举MarkerType从一开始就是零。

Thanks for the help! 谢谢您的帮助!

Your parameter shouldn't be (CLLocationCoordinate2D*)position , it should be (CLLocationCoordinate2D)position . 您的参数不应为(CLLocationCoordinate2D*)position ,而应为(CLLocationCoordinate2D)position Then you can stop passing the pointer. 然后,您可以停止传递指针。

Your problem is more likely to be around gmsm.position = *(lm.Position); 您的问题更有可能是gmsm.position = *(lm.Position); or (*lm.Position).latitude, (*lm.Position).longitude . (*lm.Position).latitude, (*lm.Position).longitude Basically, stop using pointers to the location structs as somewhere you're getting things mixed up and accessing the wrong memory location (looks like dereferencing the valid pointer to the CustomMarker instance). 基本上,不要在位置混乱的地方使用指向位置结构的指针,而是访问错误的内存位置(就像取消引用指向CustomMarker实例的有效指针一样)。

If you are passing projection as &projection , then it generally means that the initWithTEN... method it's being passed to might want to change projection for some reason. 如果将投影作为&projection传递,则通常意味着传递给它的initWithTEN...方法可能出于某些原因想要更改投影。 Check the documentation or if you have the source, check in that method. 检查文档,或者如果您有资料来源,请使用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM