Search by Distance

Distance Search provides the capability to find and display records based on their distance from a particular center of origin.

The Distance Search feature is available depending on your pricing plan. To get started, first check that your plan includes Distance Search, and then open a Support ticket for Caspio to upload a reference table of U.S. ZIP codes into your account.

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:

Search_by_distance_1

  1. Click on the DataPages section and click New DataPage.
  2. Select Reports on the left menu and click Tabular.
  3. On the DataPage Data Source screen, you can set the data source, Style, Localization, and level of security access.
  4. 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.
  5. 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.
  6. 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.
  7. 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.

8.  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.
  • 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. The Logic tab must be correctly setup and there should be no loose elements or operators, or otherwise you won't be able to leave the tab.

       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.
Search_by_distance_9

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.
Search_by_distance_11

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.

Search_by_distance_12

12. Once finished, click Preview to view your report and enter a ZIP code in the search form:

Search_by_distance_13

After clicking Search, results are sorted by distance.

Search_by_distance_14

Click Details of any record to view the details page of a particular hospital.
Search_by_distance_15