CLLocationCoordinate2D is a struct , i.e. a value type. It is passed by value, which is another way of saying “copy”. If you assign your fields (for example, longitude), all that will do is change the copy; The original coordinate inside your Annotation will remain intact. This is why the property is not assigned.
To fix this, you must 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]; } ...
source share