表达式不可分配,坐标属性来自MKAnnotation类委托 [英] Expression is not assignable, coordinate attribute from MKAnnotation class delegate
问题描述
我这样做是为了更好地解释我的烦恼。
I did this schema in order to explain better what is my troubles.
那么,我该如何解决呢?谢谢=)
So, what can I do to fix it? Thank you =)
推荐答案
CLLocationCoordinate2D
c> struct ,即值类型。它通过价值传递,这是另一种说法复制的方式。如果您指定其栏位(例如经度),则只需修改副本;您的注释
中的原始坐标
将保持不变。
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
现在您的XML解析器代码可以: / p>
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];
} ...
这篇关于表达式不可分配,坐标属性来自MKAnnotation类委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!