"is the distance between two (lat,long) positions less than X km?"
* postgres contains a circle object where distance is the hypothenuse. The spherical problem using lat,long is also bidimensional. We could /just use haversine distance instead of hypothenuse.
How accurate do you need it? My website has a lot of "local" listing stuff based on a distance from the viewer and I use the earthdistance module in contrib to do it.
Given, it's not accurate enough to calculate a surgical missile strike, but for "within 20 miles" type of things it's good enough - give or take a mile.
The problem I have is to determine the location of the viewer/poster. Aside from asking precice lat/long coordinates (which no user will have any clue about), the next best thing is to rely on smartphones and their GPS - but what of regular browser/computer users? When I let google map my location it shows as San Francisco - which is about 56 miles off. So network location makes no sense for this.
I'm using a zipcode based geographical mapping, which already has flaws since a zipcode is an area, not a point. The commonly available zipcode databases give you the geographical center of the zipcode - which certainly will be some distance off from the real location.
I found that the inaccuracies work for my application - nobody cares about a few more or less miles when looking for something. The advantage is that it also protects the privacy of the poster to some degree - nobody really needs to know exactly where the post originated...
If "openbarter" is what I think it is (kinda craigslist just with bartering), I think a few miles off won't make a difference. Chances are, your members won't divulge their true location anyways. We have members from South Africa using a US zipcode - which is what ... 5000 miles off?
Earthdistance is definitely easy to deal with - just give a latitude/longitude and off you go..
Uwe
On Fri, 08/09/2013 09:29:49 PM Olivier Chaussavoine wrote:
I develope a project openbarter that needs to match objects based on a maximum distance between their positions on earth. I saw that the documentation of the extension earthdistance was interesting, but the promise was not in the code. It would be nice to have these functions available independently of sophisticated geographic systems. There is a circle object for flat two dimensional space, but earth deals with spherical caps. It would not be exact but enough to suppose that earth is a sphere and that all dimensions latitude, longitude and distance are in radian.
What would need to be done to adapt the circle type to a new type 'spherical cap' that would allow simple geographic indexing?
--
Olivier Chaussavoine
--
Olivier Chaussavoine