I did this schema in order to explain better what is my troubles.
So, what can I do to fix it? Thank you =)
Change:
puntoXML.coordinate.latitude = [valor floatValue];
to:
CLLocationCoordinate2D coord = puntoXML.coordinate;
coord.latitude = [valor floatValue];
puntoXML.coordinate = coord;
Make a similar change for the longitude
. Also note that you will need to add curly braces to the if
statements.
The CLLocationCoordinate2D
is a struct
, i.e. a value type. It is passed around by value, which is another way of saying "copying". If you assign its fields (e.g. longitude) all that would do is modifying a copy; the original coordinate
inside your Annotation
would remain intact. That is why the property is not assignable.
To fix this, you should add separate properties for latitude and longitude, and use them instead:
@interface Annotation : NSObject<MKAnnotation>
@property (readwrite) CLLocationDegrees latitude;
@property (readwrite) CLLocationDegrees longitude;
@property (nonatomic,assign) CLLocationCoordinate2D coordinate;
...
@end
@implementation Annotation
-(CLLocationDegrees) latitude {
return _coordinate.latitude;
}
-(void)setLatitude:(CLLocationDegrees)val {
_coordinate.latitude = val;
}
-(CLLocationDegrees) longitude{
return _coordinate.longitude;
}
-(void)setLongitude:(CLLocationDegrees)val {
_coordinate.longitude = val;
}
@end
Now your XML parser code can do this:
if ([llave isEqualTo:@"lat"]) {
puntoXML.latitude = [valor doubleValue];
} else if ([llave isEqualTo:@"lon"]) {
puntoXML.longitude = [valor doubleValue];
} ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With