Johny19 Johny19 - 26 days ago 18
Android Question

Storing LatLng using Android Realm

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

Area {
Latlat coord;
String name
}

Answer

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

LatLng { 
 double lat; 
 double lng; 
}

remember that Realm works with a relational database, it means that 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

Comments