View Single Post
  #8 (permalink)  
Old July 14th, 2009, 14:14
LourensGlog LourensGlog is offline
Member and Blogger
 
Join Date: Oct 2007
Location: Netherlands
Posts: 209
Groans: 0
Groaned at 2 Times in 1 Post
Thanks: 18
Thanked 31 Times in 28 Posts
Rep Power: 3
LourensGlog is on a distinguished road
Send a message via AIM to LourensGlog Send a message via Yahoo to LourensGlog
Re: Has anyone worked on location based shipment search?

I took a shot and found out it wasn't that bad after all:

Create a Shipment Saved Query and put this in Find All:

select s.shipment_gid from shipment s, location l where s.source_location_gid=l.location_gid and acos(sin(#LAT#/57.29578)*sin(l.lat/57.29578)+cos(#LAT#/57.29578)*cos(l.lat/57.29578)*cos((l.lon-#LON#)/57.29578))*3962<50

Notes:
- Just replace #LAT# (twice!) and #LON# with the lat/long of your location A.
- The 50 at the end represents the maximum distance (crow flight) - change this if needed.
- The 3962 at the end is the radius of the earth in miles
- The 57.29578 stands for 180/pi and is used to convert degrees to radians. A more accurate statement would have been 180/acos(-1), but if I used this I got 'out of range' errors.

Last edited by LourensGlog; July 14th, 2009 at 14:20.
Reply With Quote
The Following 2 Users Say Thank You to LourensGlog For This Useful Post:
neoandr (July 30th, 2009), Sachin (July 16th, 2009)