hartmut Posted June 14, 2007 Posted June 14, 2007 Hello I know we can find zip code radius on line but can it be done with a formula in filemaker? Is it that zip codes have to be converted to lat longitude coordinates to find those within a radius? Just wondering if there is a formula to find zip codes within a radius or distance between 2 zip codes. Thanks
comment Posted June 14, 2007 Posted June 14, 2007 See: http://www.fmforums.com/forum/showpost.php?post/235045/
aholtzapfel Posted June 14, 2007 Posted June 14, 2007 I have a radius search in my database. I have looked up Lat and Long from http://terraserver-usa.com/default.aspx (I have used a webviewer to scrape this site for this info). Fields needed are Lat (number) Long (Number) GlobalLat (Global, Number, Set to the Lat of the address you want to do the search on.) GlobalLong (Global, Number, Set to the Long of the Address you want to do the search on.) DistanceFromAddress (Unstored Calc, Number, Sqrt((Lat - GlobalLat)^2 + (Long - GlobalLong)^2) Sort by DistanceFromAddress (sorry can't do a find on it) and this allows you to find the closest address in your database. I guess this isn't a "true" radius search, Lat and Long do not equate to distance and the "raduis" produced in not truley a circle. But if you just want to find the closest (and you are not looking at an area near the arctic Circle) It should work reasonably well.
hartmut Posted June 14, 2007 Author Posted June 14, 2007 Thanks Both of you I have a zip code database with the latitude longitude information. I can't tell from Brian Dunnings site if it does a radius. There are no screen shots. I am trying to find the radius because the person I am writing a database for has jobs he has done in the past and he wants his clients to know people whom he has done similar work for in their radius. This helps him bid and quote. So the best thing that could be done is to query his database of jobs and find ones within a 30 mile radius of his present job. I just don't know how to go about doing that. Thanks Dave
Fenton Posted June 15, 2007 Posted June 15, 2007 There is a custom function at http://www.briandunning.com/filemaker-custom-functions/list.php DistanceBetweenPoints hartmut, I see that you don't have 8 Advanced, but I think this calculation will work in a regular calculation field; it doesn't seem recursive. I don't know its accuracy; I'm not really a math guy.
aholtzapfel Posted June 15, 2007 Posted June 15, 2007 Thanks for pointing to the Custom Function. It seems to work well (no idea how accurate it is.) I have just done a radius search using it. I replaced my "distance" calc above with the custom fuction and presto. Plug a Lat and Long into the global fields, do a find [distance field <30], and there is your found set. Oh I was wrong about not being able to do a find on the distance field, it can be done, it is just incredably slooow.
hartmut Posted June 15, 2007 Author Posted June 15, 2007 Hi Did you use it as a calculation in a field without going the custom code route? I f you did and you are willing could you post a sample file to let us see for ourselves. Thanks
aholtzapfel Posted June 15, 2007 Posted June 15, 2007 (edited) I used the custom function but, If I hadn't it should look something like this Fields Needed are Lat (number) Long (Number) GlobalLat (Global, Number, Set to the Lat of the address you want to do the search on.) GlobalLong (Global, Number, Set to the Long of the Address you want to do the search on.) And Distance (unstored calc, number, Let ( [ Lat1Rad = Lat * Pi / 180 ; Lon1Rad = Long * Pi / 180; Lat2Rad = GlobalLat * Pi / 180; Lon2Rad = GlobalLong * Pi / 180; Units = "miles"; x = Sqrt((Sin((lat1rad-lat2rad)/2))^2 + Cos(lat1rad)*Cos(lat2rad)*(Sin((lon1rad-lon2rad)/2))^2) ; DistanceRad = 2*2*Atan(x/(1+Sqrt(1-x*x))) ] ; Case ( IsEmpty (Lat) or IsEmpty (Long) or IsEmpty (GlobalLat) or IsEmpty (GlobalLong) ; "?" ; Units = "radians" ; DistanceRad ; Units = "nm" ; DistanceRad * 180 * 60 / Pi ; Units = "km" ; DistanceRad * 180 * 60 / Pi * 1.852 ; Units = "miles" ; DistanceRad * 180 * 60 / Pi * 1852000 / 1609344 ; "?" ) ) I have not tested this and most of it was copied from the custom function. (only thing I've done is point the lat and long's to fields and added Units to the Let statement) (Thank you Vaughan Bromfield) Edited June 15, 2007 by Guest Whoops I had forgot to point a couple things to the fields, sorry Fixed now.
hartmut Posted June 16, 2007 Author Posted June 16, 2007 Thank you very much for you time and knowledge Dave
Recommended Posts
This topic is 6369 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now