Added support for sort_mode `avg` for sorting by geo_distance.
Closes #2962