Storing LatLng using Android Realm

可紊 提交于 2019-12-24 08:23:38

问题


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

Area {
Latlat coord;
String name
}

回答1:


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

LatLng { 
 double lat; 
 double lng; 
}

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;
  ...
}

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



来源:https://stackoverflow.com/questions/40504576/storing-latlng-using-android-realm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!