当前位置: 动力学知识库 > 问答 > 编程问答 >

realm - Can I store objects from android SDK like Location?

问题描述:

Can I store objects from android SDK like Location in realm? If so, how can I do it? I am getting this error message Error:(14, 8) error: Type android.location.Location of field location is not supported or what could be a workaround to save a location?

网友答案:

Realm can only store classes that extends RealmObject, so it is not possible to save the android.location.Location class directly.

If you require the android Location class for some other API I would create my own Realm Location class that are able to convert it's representation, like so:

public class MyLocation extends RealmObject {

  // Duplicate all parameters required to initialise a android Location 
  private double longitude;
  private double latitude;
  ...

  // Public static method for converting object to android Location
  public static android.location.Location getLocation(MyLocation loc) {
    Location location = new Location("Realm");
    // Set all relevant location parameters
    return location;
  }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: