Search by Distance
Distance Search feature provides the capability to find and display records based on their distance from a particular center of origin. The feature Distance Search can be easily configured in Caspio Bridge without any additional programming. When Distance Search is enabled, Caspio will upload a USA ZIP Codes reference table to use as a lookup table in your Report DataPages. The Distance Search Add-on feature must be enabled in your Caspio account. Learn more about enabling Distance Search.
In this article, we will create a Report DataPage where end users enter a ZIP code to search for all hospitals located within 5 to 50 miles of the entered ZIP code. The table name is Hospital_Directory and is displayed below:
- Click on the DataPages section and click New DataPage.
- Select Reports on the left menu and click Tabular.
- On the DataPage Data Source screen, you can set the data source, Style, Localization, and level of security access.
- On the Search Type screen, you can customize how the search will be performed. You can allow users to use a search form to select and filter the Results page or automatically display results based on a pre-defined criteria. Check Allow users to select data using a search form.
- On the Select Search Fields screen, select which fields are used in your search form by moving the fields from left to right. In this example, the Distance Search by ZIP/Postal Code is selected.
- On the Configure Search Fields screen, you can configure the functionality, appearance, data validations, and other properties for your search fields. Select a field from the DataPage Elements menu on the left and configure field properties on the right.
- While implementing Distance Search, you configure the search based on geocodes or ZIP codes in the General Options section:
- My data is geocoded – If the DataPage data source includes geocoded data, select this option and select Latitude and Longitude fields in the associated dropdowns.
- Determined via postal code – If the DataPage data source includes ZIP codes, select this option and select the ZIP code field in the dropdown. In this scenario, select Determined via postal code and select the ZIP_Code field.
- In the Geocode Reference section, you can use the ZipCodesUSA lookup table from Caspio or set any other lookup table that has Postal Codes, Latitude and Longitude fields.
- In the Additional Options section, you can set the Distance units as Miles or Kilometers.
- Click Center of Search under the DataPage Elements panel. If the search is based on ZIP codes, the Center of Search should be a ZIP code.
- You can also configure the Distance field. In this scenario, the label is Maximum Distance and the form element has been changed to Dropdown. Custom values are entered in the Field Options section.
- If Distance Search by Coordinates was selected as a search field instead, then the search form will have Center Latitude and Center Longitude fields. They can be configured based on the requirements of your application.
9. On the Select Results Page Fields screen, you can select the desired fields from your data source to display in your results page. In this scenario, only three fields are selected to display on the results page. All fields will be selected later for the details page.
10. 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.
11. You have the option to add a details page to your Report DataPage that is linked to each search result. In this scenario, check Yes, enable Details Page and configure the Details page normally.
13. Once finished, click Preview to view your report and enter a ZIP code in the search form:
After clicking Search, results are sorted by distance.
Click Details of any record to view the details page of a particular hospital.