Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new CLLocationCoordinate2D at custom Latitude/Longitude

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.

like image 413
Karoly S Avatar asked Jul 18 '11 21:07

Karoly S


4 Answers

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.

like image 189
Firoze Lafeer Avatar answered Nov 17 '22 22:11

Firoze Lafeer


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>
like image 22
Pedro Romão Avatar answered Nov 17 '22 21:11

Pedro Romão


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];
}
like image 4
Kal Avatar answered Nov 17 '22 22:11

Kal


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;
like image 2
Joris Mans Avatar answered Nov 17 '22 21:11

Joris Mans