Closed xnzac closed 10 years ago
Not sure how to add this to a github message, but I resolved the issue by reversing the regressive commit: https://github.com/zaczheng/geokit-rails/commit/15dd4b6d1615c77563438bd968e3912f455b1adc
And then 'distance' is back!
+1 on this. @zaczheng 's fix works - can you do a PR on this?
The repo owner wanted to extract the distance calculation out. See the following commit:
https://github.com/geokit/geokit-rails/commit/f79bbdfb81d2a87c24c152cbfbf1638f2eacd878 "I've pushed a new commit with a helper method and some tests and removes the Array sort_by_distance_from method alltogether."
I'm open to PRs but overriding core classes is best avoided for specific uses.
Yes, so the new way of doing it (see test in commit referenced above) is: unsorted_collection = DistanceCollection.new(unsorted) unsorted_collection.set_distance_from(locations(:a)) unsorted_collection.sort_by(&:distance)
I would happy accept something like:
class DistanceCollection
def sort_by_distance_from(origin, opts = {})
set_distance_from(origin)
sort_by(&:distance)
end
end
This would enable a shorter usage like:
DistanceCollection.new(unsorted).sort_by_distance_from(origin)
Is there no way to get the actual distance? I don't want to sort by distance i want to display the distance to my user, I need the actual field... how to get the distance field?
@speakingcode did you figured it out? i need help 😞 @mnoack
Did anyone figured it out? @ccoeder ?
You can look at this issue, there is patch on that https://github.com/geokit/geokit-rails/issues/56
As documented:
The plug-in creates a calculated distance field on AR instances that have been retrieved throw a Geokit location query. By default, these fields are known as "distance" but this can be changed through the :distance_field_name key.
"distance" field on returned objects is not available.