Realm是否支持持久保存第三方Parcelable对象(例如Maps API中的MarkerOptions类)?
因此,我正在为Android构建路线规划应用程序,我需要保留Maps API中的LatLng,MarkerOptions和Polyline对象列表 - 所有这些都实现了Parcelable。我以为我会尝试使用Realm来保留对象列表。
我在Realm中阅读了Parceler库支持,并试图在Realm中保留一个包含LatLng对象的Parcelable类。
$this->context->message2
编译未完成此错误
import io.realm.RealmObject;
import io.realm.SavedLocationRealmProxy;
@Parcel
public class SavedLocation extends RealmObject{
private String locationName;
private LatLng location;
private String areaName;
public SavedLocation() {
}
public SavedLocation(String locationName, LatLng location) {
this.locationName = locationName;
this.location = location;
}
public SavedLocation(String locationName, LatLng location, String areaName) {
this.locationName = locationName;
this.location = location;
this.areaName = areaName;
}
...
我还尝试按照Realm documention
的指示添加此注释Error:(7, 8) error: Type com.google.android.gms.maps.model.LatLng of field location is not supported
但是,由于包含LatLng类,因此无法创建SavedLocationRealmProxy。
是否提供了对Parceler的支持,以使RealmObjects可以在Realm中保持可分割或Parcelable对象?
谢谢..
答案 0 :(得分:0)
Parceler的支持允许RealmObjects在Intents / etc中被分配(如CommonsWare在评论中指出的那样)。请注意,当RealmObjects被分区时,Realm对象将与Realm断开连接。
为什么会收到此错误?
LatLng不会展开RealmObject
。因此无法保存到Realm。为了保存您的LatLng对象,您需要创建自己的LatLng对象(如MyLatLng
或其他东西)并将其映射。
如果您正在寻找一个关于Realm的Geo Points的好例子,您可以在这里查看Thorben Primke的realm-mapview示例:https://github.com/thorbenprimke/realm-mapview
在相关的说明中,可以在此处跟踪Realms地理点支持:https://github.com/realm/realm-java/issues/1772