Just started playing with geokit and trying some things out...
Things are pretty much working as expected, given a point, its finding things nearby.
However, if I set :wit开发者_StackOverflow社区hin to be a large value, say 100,000, using :miles, I would expect to get most (if not all) of the objects in the db returned - but it seems to stop at a certain point - as if there is a built in maximum for :within.
I have tried the formulas :flat and :sphere.
Thanks in advance, Chris
Your problem doesn't appear to be a built in maximum for :within
but the lack of a limit (and sanity checking inside geokit).
It looks like a :within
query ends up going through Geokit::Bounds.from_point_and_radius
to produce a bounding box. from_point_and_radius
will do a bit of trigonometry (see endpoint
in mappable.rb
) and the result will be an Geokit::Bounds
instance.
I suspect that things are going wrong for you in the trigonometry; trig functions are periodic so your 100 000 radius will end up wrapping around to something between 0 and ~40 000 km (the Earth's circumference, ~25 000 miles) and the bounding box will not bound 100 000 miles. If you play with your 100 000 a bit you could probably get geokit to produce a bounding box that is only a couple centimeters per side (or a zero radius if you can sort out the usual floating point issues).
Executive summary: if you want them all, don't use :within
at all; if you want to use :within
, then give it a sensible distance (i.e. small enough to fit on the planet's surface without wrap around).
精彩评论