Working on a presentation for a customer that employs the Cluster Maps concept, the request came up about doing perimeter searches—as in ‘How do I see all the related addresses around a specific location?” This ability would aid sales people in the field, cut down on travel etc. A search on Brian Dunning’s very useful Custom Functions collection, I found just what I needed to create these searches.
Download the updated Cluster Maps Demo file here.
Adding Perimeter Search to the Cluster Maps Demo
Clicking ‘Perimeter Search’ button on any address record will result in a perimeter search and display this information on a map in a Web Viewer.
Enter the number of miles you want the perimeter to be surrounding your target address.
Search Result in a new Web Viewer Window
1) Note that the Window title will display the number of found records.
2) The Bounding Box Longitude/Latitude information is displayed here.
3) Google Map search with resulting found records displayed in a cluster.
So how does this work? Start by adding the Custom Function to your database.
Adding a Custom Function
You will need a copy of FileMaker Pro Advanced to access the Custom Functions area in your database. Use the File menu, to select Manage and then Custom Functions… from the popup.
The Custom Function
The function was written by Steve Murray.
It is possible to copy and paste Custom Functions in FileMaker 12 or if you are interested in the details, you can copy and paste the code into the three fields in the Custom Functions definition dialog box.
Details of the Custom Function
Who knows how ‘GeoBox’ works its magic or even if it is totally accurate. It does seem to give the general vicinity, which is probably all you are looking for in most cases.
A Custom Function consists of
1) Function Name
2) Function Parameters and
3) the code to execute using those Parameters.
The Perimeter Search script
A script called “Perimeter Search” has been added to the Cluster Maps database.
Search script using the calculated bounding box from the Custom Function
How the script works:
- Display a dialog box with an input field, in this case gPerimeterDistance, a global field defined to hold the distance of the perimeter.
- A script variable is set to the bounding box, the result will be four values in a list.
- Values from the bounding box are employed in the search, employing the GetValue function.
- A new window is opened with the Found Count displayed in the title.
- ‘Generate JSON HTML and Display Map’ script is run with a script parameter so the window will display in a Web Viewer.
- A Global Variable is set to display the Bounding Box on the layout.
How to use the GeoBox Custom Function
Bonus Tip: Convert search to Kilometers notes in the variable definition rather than messing with the Custom Function.
Update 2013-06-25 – Updated Demo File. Fixed a bug in the Get Coordinates script. Filtering on the number string and managed to leave out the number 8. I figured 8 doesn’t get used that often and how much could it throw things off?
Also, thanks to reader Henry Rose of MacWizard, discovered that Google returns inconsistent JSON files, so adapted the parsing to narrow the focus on the most accurate Longitude and Latitude numbers of the three returned. Also realized that the Web Viewer on the Map Detail layout was using a calculated address lookup URL rather than a longitude/latitude search. Switched to the more accurate long/lat search. Added a Show on Map button to view single searches in a web browser.
Cluster Maps – Update – Fixed Popup Formatting Bug