How to Target Gravity Forms Address Autocomplete to Specific Locations
Show Address Autocomplete suggestions only for the places you actually need—by country, radius, city, or even by place name.
GP Address Autocomplete lets you type a few letters, get location suggestions, and fill an entire Address field with a single click. Pretty magical stuff.
Out of the box, it pulls in suggestions from all over the globe. Handy if you’re, for example, shipping worldwide. But if you only serve a specific area, you’ll want to narrow those results down so users only see addresses that’s relevant to them.
Here’s what we’re covering:
- Filtering by country
- Restricting each field to a specific country
- Setting a radius boundary around an area
- Autocompleting by city only
- Searching places by name
- Capturing apartment/unit numbers
Let’s teach your Address fields some boundaries—literally.
This article requires the Gravity Forms Address Autocomplete perk.
Buy Gravity Perks to get this perk plus 50 other premium Gravity Forms plugins!
Filter by Country
First things first: make sure Address Autocomplete is enabled. If it’s your first time, check out our quick setup guide to get it up and running.
Let’s say you’re only shipping to Southeast Asia, or maybe you’re running a regional campaign. You can flip on the Countries filter to limit suggestions to specific countries. Once enabled, it’ll apply to every Address field on your site with Address Autocomplete enabled (or use one of the snippets below to tweak fields individually).
Here’s how:
- In your WordPress dashboard, go to Forms › Settings › Autocomplete.
- Under Countries, select the country/ies you need. (Google only supports up to 5 countries at a time).

Set Location Boundaries
These next tricks let you fine-tune autocomplete suggestions to the area you need.
Restrict By Country
Working with multiple Address fields? You can restrict each field to a specific country so users only see relevant suggestions. This is handy for scenarios like collecting shipping and billing addresses for different regions.
This trick uses JavaScript, so you’ll need Code Chest—our handy tool that lets you add and organize JavaScript and CSS snippets right in Gravity Forms. Just open your Spellbook › activate GF Code Chest.
gform.addFilter( 'gpaa_autocomplete_options', function( autocompleteOptions, gpaa, formId, fieldId ) {
// Update "1" to your Address field ID.
if ( formId != GFFORMID || fieldId != 1 ) {
return autocompleteOptions;
}
if ( typeof autocompleteOptions.componentRestrictions !== 'object' ) {
autocompleteOptions.componentRestrictions = {};
}
// Update "DE" to the country to which you would like to restrict results.
autocompleteOptions.componentRestrictions.country = [ 'DE' ];
return autocompleteOptions;
} );
How to use:
- Copy the snippet above.
- Open Code Chest and paste it inside the JavaScript box.
- Change
1to your Address field ID. - Replace
DEwith your Alpha-2 country code. - Click Save Settings.
Note sure which code to use? Here’s a handy list of country codes.

Set a Radius Boundary
This snippet lets you draw an invisible circle around any location. Just choose your center point, set the radius, and only addresses within that circle will show up. This is useful for local businesses that only serve a specific area—like a pizza shop that only delivers within five miles!
This snippet uses PHP, so you’ll need Code Snippets—a free WordPress plugin that lets you add PHP code easily. Just head to Plugins › Add New, search for Code Snippets, then install and activate.
add_action( 'gform_pre_enqueue_scripts_123', function() {
?>
<script>
gform.addFilter( 'gpaa_autocomplete_options', function( options, gpaa, formId ) {
// Update miles to the average
var miles = 100;
var centerLat = 34.5199;
var centerLng = -105.8701;
var metersInMile = 1609.344;
var autocompleteCircleBounds = new google.maps.Circle( { center: new google.maps.LatLng( centerLat, centerLng ), radius: miles * metersInMile } );
options.bounds = autocompleteCircleBounds.getBounds();
options.strictBounds = true;
return options;
} );
</script>
<?php
} );
How to use:
- Copy the snippet above.
- Open Code Snippets, add a new snippet, and paste it.
- Change
123to your form’s ID. - Set
milesto your desired radius. - Set the
centerLat(latitude) andcenterLng(longitude) to your center point. - Click Save and Activate.
If you’re not sure where to get coordinates, right-click any location in Google Maps and copy the latitude and longitude that appears.
Pro-tip
You can pair this with GP Bookings to create location-aware scheduling that only shows slots for your service area.
Autocomplete by City Only
Just need the city? Maybe you’re running a regional survey or grouping users by location. This snippet lets you capture only the city, state, and country.
You’ll need Code Snippets for this once since it uses PHP.
How to use
- Copy the full Autocomplete by City snippet here.
- Paste the snippet into Code Snippets.
- Scroll to the bottom of the code snippet and find this “Configuration” section:
# Configuration
new GPAA_Autocomplete_By_City( array(
'form_id' => 123, // Update "123" to your form ID.
'field_id' => 4, // Update "4" to your Address field ID.
) );
- Change
123to your form’s ID. - Change
4to your Address field’s ID. - Click Save and Activate.

Target by Place Name and Unit Number
These tricks help you find the exact address by searching for a place’s name or by including the apartment or unit number. 📍
Search by Place Name
When booking appointments, ordering delivery, or visiting a place, people naturally think of destinations by name first (like “Starbucks” or “Central Park”) rather than the street address. You can do this by using a snippet that lets you search and show places by name, instead of typing the street address.
This one uses JavaScript, so you’ll need to use Code Chest.
gform.addFilter( 'gpaa_autocomplete_options', function( options ) {
options.types = [ 'geocode', 'establishment' ];
options.fields.push( 'name' );
return options;
} );
// Display Place Name
gform.addAction( 'gpaa_fields_filled', function ( place, instance, formId, fieldId ) {
let $addressLine1 = jQuery( '#input_{0}_{1}_1'.gformFormat( formId, fieldId ) );
$addressLine1.val( place.name + ', ' + $addressLine1.val() ).trigger('change');
} );
How to use:
- Copy the snippet above.
- Open Code Chest and paste it inside the JavaScript box.
Click Save Settings.

Always Capture Unit Numbers
In some countries, Google’s Places API leaves out the unit or apartment number when autocompleting an address. For example: “45 Collins Street, Melbourne” is different from “45 Collins Street, Unit 12, Melbourne.”
That missing unit number is critical for deliveries and billings, as packages can get lost or end up at the wrong door. This snippet makes sure the unit number is always included!
This trick uses JavaScript, so you’ll need to use Code Chest.
How to use:
- Copy the Always Use Unit Numbers snippet here.
- Open Code Chest and paste the snippet.
- Click Save Settings.
Done! Who says geography class is for humans only?
– Address fields 🗺️
