Creating a new CLLocationCoordinate2D at custom Latitude/Longitude

Karoly S picture Karoly S · Jul 18, 2011 · Viewed 56.5k times · Source

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.

Answer

Firoze Lafeer picture Firoze Lafeer · Jul 18, 2011

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.