表达式不可分配,坐标属性来自MKAnnotation类委托 [英] Expression is not assignable, coordinate attribute from MKAnnotation class delegate

查看:183
本文介绍了表达式不可分配,坐标属性来自MKAnnotation类委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做是为了更好地解释我的烦恼。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆