使用Android Realm存储LatLng [英] Storing LatLng using Android Realm

查看:106
本文介绍了使用Android Realm存储LatLng的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在存储包含Google的LatLng对象和Realm的RealmObject方面,有什么更清洁的方法?

What is there cleaner whay of storing a RealmObject that contains a Google's LatLng object int Realm?

Area {
Latlat coord;
String name
}

推荐答案

尽管将数据另存为对象似乎很自然

Although it might seem natural to save the data as an object

LatLng { 
 double lat; 
 double lng; 
}

请记住,Realm是对象存储-如果创建对象,则它将存储在表(实体)中.正如穆罕默德·拉(Mohammed Ra)的建议(在上面的评论中),您应该存储一个对象,其中包含纬度和经度字段,都为double

remember that Realm is an object store - if you create an object, it will be stored in a table (entity). As suggested by Mohammed Ra (in the comment above), you should store an object which contains the fields latitude and longitude, both as double

class Area extends RealmObject {
  double lat; 
  double lng;
  String name;
  ...
}

此解决方案还提高了涉及坐标的查询的性能-在这种情况下,您应该在坐标上加上@Index注释.

This solution also improves the performance of queries involving the coordinates - in which case you should put @Index annotation on them.

这篇关于使用Android Realm存储LatLng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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