32

I feel bad for asking this because it seems to be such a simple thing to get hung up on, but I've looked at every relevant resource I could, tried as many of the combinations for solutions that i've seen others use, and nothing has worked...

I am trying to iterate through some XML that I recieve and parse out the Latitude and Longitude of a coordinate in the XML, and store it in an array from which I will then plot it.

My problem is that no matter what type I use, how I cast it, what have you, xcode ALWAYS finds some sort of issue with it.

Relevant part of my .h file:

CLLocationCoordinate2D Coord;
CLLocationDegrees lat;
CLLocationDegrees lon;

@property (nonatomic, readwrite) CLLocationCoordinate2D Coord;
@property (nonatomic, readwrite) CLLocationDegrees lat;
@property (nonatomic, readwrite) CLLocationDegrees lon;

Relevant part of my .m file:

else if ([elementName isEqualToString:@"Lat"]) {
        checkpoint.lat = [[attributeDict objectForKey:@"degrees"] integerValue];
}
else if ([elementName isEqualToString:@"Lon"]) {
    checkpoint.lon = [[attributeDict objectForKey:@"degrees"] integerValue];
}
else if ([elementName isEqualToString:@"Coord"]) {
    checkpoint.Coord = [[CLLocation alloc] initWithLatitude:checkpoint.lat longitude:checkpoint.lon];
}

The current error that I am getting is: "Assigning to 'CLLocationCoordinate2D from incompatible type 'id''. I take that to mean that the return value of the initialization function is incorrect, but I have no idea why since its a built in function...

I have also tried what would make the most sense to me that I saw someone else doing:

checkpoint.Coord = CLLocationCoordinate2DMake(checkpoint.lat, checkpoint.lon);

While that returns no immediate errors, when I try to build and run it gives me:

Undefined symbols for architecture i386: "_CLLocationCoordinate2DMake", referenced from: -[XMLParser parser:didStartElement:namespaceURI:qualifiedName:attributes:] in Checkpoint.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

Any help/clarification/nudges in the right direction would be very much appreciated because I am very out of ideas at this point.

1
  • 5
    Never feel bad for asking such simple questions; that's what we're here for.
    – Mick Byrne
    Feb 13, 2013 at 11:13

4 Answers 4

50

What made the most sense to you (CLLocationCoordinate2DMake) is correct. You just forgot to include the CoreLocation framework in your project.

And, as others have pointed out, your lat/lon in your file are probably not integers.

1
  • Ah that makes sense, I figured that it had to do with a missing framework >.< Thank you! I'm probably going to go with this because trying to set them any other way still gives me errors.
    – Karoly S
    Jul 18, 2011 at 22:31
10

what i did was: first create a CLLocationCoordinate2D:

CLLocationCoordinate2D c2D = CLLocationCoordinate2DMake(CLLocationDegrees latitude, CLLocationDegrees longitude); 

my latitude and longitude are double types.

in your Imports be sure Mapkit library is imported.

#import <MapKit/MapKit.h>
4

This should work.

CLLocationCoordinate2D center;
.....
else if ([elementName isEqualToString:@"Lat"]) {
    center.latitude = [[attributeDict objectForKey:@"degrees"] doubleValue];
}
else if ([elementName isEqualToString:@"Lon"]) {
    center.longitude = [[attributeDict objectForKey:@"degrees"] doubleValue];
}
1
  • Hey Kal, thanks for the quick response but unfortunately I'm getting the same error set that Joris's suggestion gets me. If you(or Joris) have any ideas about why, I'd love to give them a shot. Thanks!
    – Karoly S
    Jul 18, 2011 at 22:34
2

try changing

[[attributeDict objectForKey:@"degrees"] integerValue]

into

[[attributeDict objectForKey:@"degrees"] floatValue]

also

checkpoint.Coord = [[CLLocation alloc] ....

can't be correct as you defined Coord as being CLLocationCoordinate2D, which is

  • not a CLLocation
  • not a class but a struct

what you should do is:

    CLLocationCoordinate2D coordinate;    

    else if ([elementName isEqualToString:@"Lat"]) {
        coordinate.latitude = [[attributeDict objectForKey:@"degrees"] floatValue];
    }
    else if ([elementName isEqualToString:@"Lon"]) {
        coordinate.longitude = [[attributeDict objectForKey:@"degrees"] floatValue];
    }

    checkpoint.Coord = coordinate;
2
  • Hey Joris, thanks for the quick reply! I appreciate the clarification and it makes quite a bit of sense. I gave the changes you suggested a shot and I ended up getting a "Expression is not assignable" error. My code is identical to what you suggested, I don't really have any idea why xcode doesnt approve. If there is any way I could give you more information let me know, and I'll edit the main question! Thank you!
    – Karoly S
    Jul 18, 2011 at 22:24
  • Realize this is pretty old, but the CLLocationDegrees type (which CLLocationCoordinate2d is made up of) is a double rather than a float...depending on how much resolution you need, you want to call doubleValue instead of floatValue.
    – Reid
    May 29, 2014 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.