且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何按距离对RealmList或RealmResult进行排序?

更新时间:2022-04-03 22:55:29

像这样的事情确实需要地理空间支持才能以任何有效的方式工作.

Something like this really requires Geo spatial support to work in any efficient manner.

现在,我认为您***的选择是从Realm中复制数据,并在辅助线程中进行手动处理.

Right now I think your best bet is copying the data out of Realm and do manual processing in a worker thread.

如果在HandlerThread中实现它,则可以执行类似的操作

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>>() {
  @Override
  public void onChange(RealmResults<City> cities) {
    List<City> standaloneCities = realm.copyFromRealm(cities);
    doManualSorting(standaloneCities);
    sendToUiThread(standaloneCities);
  }
});