Search by Distance
Distance Search provides app users the capability to find and display records based on their distance from a particular location.
The Distance Search feature availability depends on your account plan. For certain usage scenarios you may also need a geocoded table of ZIP codes of your country or region. Caspio Support can provide a table of U.S. ZIP codes to customers who have distance search feature available in their plan.
Note that Caspio provides geocoding service to automatically append geocoding to your address centric databases. Contact us for more information.
In this article, we will create a Report DataPage where app users enter a ZIP code to search for all hospitals located within 50 miles of the ZIP code. The table name is Hospital_Directory and its design is displayed below:
Steps for creating a search by distance DataPage. Many options that are not relevant to this article are skipped. See a full explanation of Search and Report DataPages to learn more.
- In an app, from the sidebar, click on the DataPages and then click New DataPage.
- Select Reports on the left menu and click Tabular.
- On the DataPage Data Source screen, you can set the data source mentioned above. Leave others according to defaults or customize as you wish.
- Next, on the Search Type screen, select the option for a search form, click Next.
- On the Select Search Fields screen, select Distance Search by ZIP/Postal Code. If you do not see this option you must select a plan that provides Search by Distance. Contact Caspio if you need help.
- On the Configure Search Fields screen, we can configure the specifics of our search by distance.
There are two high level options to choose from:
- My data is geocoded – If our Hospitals table was geocoded and contained latitude and longitude for each hospital we could select this option as it provides the most accurate distance calculation.
- Determined via postal code – This is an alternative option for when our data is not geocoded. It does require ZIP code for each and along with our U.S. ZIP codes table we can setup search by distance.
In this example, we use Determined via postal code option.
In the Geocode Reference section, we use the ZipCodesUSA lookup table that is provided by Caspio and set the ZIP code, latitude and longitude fields accordingly.
In the Additional Options section, we can set the Distance units as Miles or Kilometers.
- The next step is to configure the Center of Search in the DataPage Elements panel. If the search is based on ZIP codes, the Center of Search should be a ZIP code. This is the value the app user provides in the search form interactively.
- The next step is to configure the Distance field. In this scenario, the label is Distance and the form element is set to Dropdown. Dropdown choices are entered.
- If on the previous screen Distance Search by Coordinates had been selected, the search form would have consisted of Center Latitude and Center Longitude fields. They can be configured based on the requirements of your application. A Tech Tip article is available that shows how a search form with an address field can be used instead of latitude and longitude fields.
- Distance Search can be further tailored in the Logic tab. This provides you with unlimited ways to create complex logic in the way the search works. Refer to the article on Logic for additional information.
7. The next screen is for selecting the fields for the results page.
8. On the Configure Result Page Fields, you can render the appearance, formatting and other properties for each field that was selected on the previous screen. You can also add the Calculated Distance field to your results page using the insert button . Calculated Distance field in the results page shows the distance of each displayed record from the center of the search.
9. On the Search Results Options screen, Interactive Reporting Options are available for further configuration. Note that in the sorting area you can choose the calculated distance to order results by distance.
10. The remainder of the DataPage wizard can be setup as you wish.
This is how this DataPage works for the app user. The search form asks for the ZIP code and maximum distance.
And the search result is displayed along with the distance of each hospital from the provided ZIP code.
And the results can be drilled down to the Details of a particular hospital.