Page 1 of 1

Add Zip Code/Distance function to Find page

PostPosted: Sat Aug 13, 2011 9:21 am
by manifold
Hello all,

I am looking to create a calculation function and a search function for my database, and ideally add it to the Find page (or, alternatively, to a separate page accessible via menu tabs).

First, I need to calculate the number of fire departments within a certain distance of a zipcode that have certain types of equipment. For instance, how many fire departments within 10 miles of zip code 07075 have a NIMS Type I Fire Engine? So, I would need to enter a central zip code, specify a search radius, match the zip code to coordinates, run the coordinates through an algorithm/function, and get the list of results.

I have what looks to be a great php function from Micah Carrick (http://www.micahcarrick.com/php-zip-cod ... ation.html); I also have a listing of US fire departments with zip codes and a listing of US zip codes with coordinates (both of which are already installed in my database). Perhaps someone has some experience in working with this?

Second, I need to figure out where within Xataface to incorporate this function.

Any thoughts on how to get started would be appreciated!

TYIA,
-manifold

Re: Add function to Find page

PostPosted: Sat Aug 13, 2011 9:53 am
by shannah
The way I would look at this problem is in terms of longitude and latitude. Your database should store the longitude and latitude coordinates of each fire department. Then you'll be able to search on ranges of those to zero in on any rectangular region.

The second part is you need to be able to convert from a ZIP code to a longitude/latitude range. You also need to be able to perform some arithmetic with longitude and latitude. E.g. Given a latitude of X. What is the latitude 5 miles north of X. etc...

Once you have all of those pieces in place (and none of that should be too tricky... I've run across a fair number of databases in the public domain to convert zip codes to longitude/latitude -and the arithmetic is not that hard), you can create an action that takes a zip code and a radius as input, and produces longitude and latitude ranges either forwards to the list view for that result set - or returns the results directly. You can also look at implementing a slot or block on the find form to insert your "widget" for this.

-Steve