How Do You Sort A Realmlist Or Realmresult By Distance?
Given a RealmObject that has the fields latitude and longitude and you have a RealmList or a RealmResult of such objects. How do you sort by distance by for example your current Lo
Solution 1:
Something like this really requires Geo spatial support to work in any efficient manner.
Right now I think your best bet is copying the data out of Realm and do manual processing in a worker thread.
If you implement it in a HandlerThread you can do something like this
RealmResults<City> results = realm.where(City.class).findAllAsync();
results.addChangeListener(new RealmChangeListener<Results<City>>() {
@Overridepublic void onChange(RealmResults<City> cities) {
List<City> standaloneCities = realm.copyFromRealm(cities);
doManualSorting(standaloneCities);
sendToUiThread(standaloneCities);
}
});
Post a Comment for "How Do You Sort A Realmlist Or Realmresult By Distance?"