Nearest Locations Field
The Nearest Locations Field finds nearby destination records from a visitor's origin, displays the results on a map, and saves the selected location with the Gravity Forms entry. Destinations can be entered manually or loaded from a database table, filtered by straight-line distance, and optionally refined with Google Routes API travel distance and duration.
Nearest Locations Field Overview
The field uses a linked Geocoder Field as the search origin. It compares that position with a configured list of destinations, orders eligible results by distance, and lets the visitor select one location. The selection can populate other Geocoder Fields, highlight a marker, appear in a dedicated Nearest Locations Panel, populate Dynamic Fields, and be stored with the entry.
Required and Optional Fields
- Required: A Geocoder Field that supplies the origin coordinates.
- Optional: A Map Field for destination markers.
- Optional: A Nearest Locations Panel Field for the selected-location summary.
- Optional: One or more output Geocoder Fields that should receive the selected destination.
Nearest Locations Field Settings
Location Source Formats
Manual Locations
Enter one destination per line using pipe-separated key/value pairs, CSV, or JSON. Coordinates are required and the coordinate keys must match the Latitude Column and Longitude Column settings. Other values such as title, address, category, note, or icon may be included for templates and saved output.
latitude:40.7128 | longitude:-74.0060 | address:New York, NY | title:Office
latitude:47.6062 | longitude:-122.3321 | address:Seattle, WA | title:Support CenterDatabase Table
Enter a valid table name and the columns that contain latitude and longitude. This is an advanced source intended for an existing table on the WordPress database. The server resolves the form's saved configuration; visitors do not choose the table or columns.
Straight-Line and Routes API Results
Every search can use Haversine straight-line distance to find and pre-sort nearby destinations. When Use Matrix API is enabled, the field sends the top eligible candidates to the Google Routes API to obtain route-aware distance and duration. The matrix threshold limits which straight-line candidates are sent, and the matrix limit caps the request at 25 locations.
If route-matrix data is unavailable, the field preserves the straight-line results and reports the matrix problem rather than discarding the entire nearest-location search.
Selection, Saved Data, and Merge Tags
Selecting a result saves that location and its calculated values, updates linked output fields, and changes the selected marker when configured. Entry details display the selected location.
The default merge tag returns formatted HTML. Available modifiers include html, text, json, distance, duration, address, or any saved location key such as title. For example, {Nearest Location:10.distance} returns the formatted distance for field 10.
Basic Setup
- Add an origin Geocoder Field and connect it to the address or map inputs used by the visitor.
- Add the Nearest Locations Field and select the origin Geocoder Field.
- Choose Manual Locations or Database Table and configure valid destination coordinates.
- Set the result limit, optional radius, and measurement system.
- Optionally add and connect a Map Field, Nearest Locations Panel, and output Geocoder Fields.
- Enable Routes API Matrix only when route-aware distances or durations are needed.
- Save and test searches from several origins, including a location with no result inside the radius.
Troubleshooting
- No search runs: Verify that the origin Geocoder Field has numeric latitude and longitude values.
- Manual destinations are ignored: Make sure every record has coordinate keys matching the Latitude Column and Longitude Column settings.
- A database source fails: Verify the table and column names and confirm that the database user can read the table.
- Markers do not appear: Select a Map Field and confirm that the destination coordinates are valid.
- Matrix results are unavailable: Enable the Google Routes API for the applicable API key and verify its restrictions. Straight-line results can still be used.


