简体   繁体   中英

CLLocationCoordinate2D gets weird values after being passed

It's my first time programming for IOS in objective C, so please bear with me.

Basically, my values of my CLLocationCoordinate2D change by themselves after passing the objects.

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.

Another issue I'm having is that the enum MarkerType is nil from the very beginning.

Thanks for the help!

Your parameter shouldn't be (CLLocationCoordinate2D*)position , it should be (CLLocationCoordinate2D)position . Then you can stop passing the pointer.

Your problem is more likely to be around gmsm.position = *(lm.Position); or (*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).

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. Check the documentation or if you have the source, check in that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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