Changing the address that GravityView Maps geocodes
GravityView Maps turns an entry’s address into a latitude and longitude before it can put the entry on a map. These PHP filters change the address it looks up:
gravityview/maps/marker/field-valuereceives the parts of the Address field, such as the street, the state and the country.gravityview/maps/marker/addressreceives the address as one line of text.
The address they return is looked up only for an entry with no saved position yet. Entries that were looked up before you added the code keep their pins until you geocode them again.
Pins at the center of the state or country #
A directory of people, such as mentors, volunteers or members of a support group, can show roughly where each person is without showing where they live. This code geocodes only the State / Province and Country of the Address fields of one form, so each pin lands at the center of the state or province:
/**
* Geocodes only the State / Province and Country of the Address fields
* of one form, so map pins land at the center of the state or province.
*
* @param array|string $field_value The parts of the Address field, by input ID.
* @param array $entry The entry.
* @param GF_Field $field The Address field.
*
* @return array|string The parts to geocode.
*/
add_filter( 'gravityview/maps/marker/field-value', function ( $field_value, $entry, $field ) {
// Replace 12 with the ID of your form.
if ( 12 !== (int) rgar( $entry, 'form_id' ) || 'address' !== $field->type ) {
return $field_value;
}
// Input .4 is the State / Province and .6 the Country.
return array(
$field->id . '.4' => rgar( $entry, $field->id . '.4' ),
$field->id . '.6' => rgar( $entry, $field->id . '.6' ),
);
}, 10, 3 );Note: Adding custom PHP code snippets to your website shows where to put this code.
For example, 1120 SW 5th Ave, Portland, Oregon 97204 is looked up as Oregon United States, and its pin lands in the middle of Oregon. An address with no state, such as one in Manchester, England, is looked up as United Kingdom and lands in the middle of the country.

Limits of the code
The entry keeps its full address, and a View that shows the Address field shows all of it. Leave the Address field out of the View if visitors shouldn’t see it.
With Enable GravityView Maps geolocation autocomplete checked on the Address field, the form saves the exact position of the address a visitor picks, and the code doesn’t change it. To turn the setting off:
- Go to Forms and click the form’s title to open the form editor.
- Click the Address field.
- Under Field Settings, in General, uncheck Enable GravityView Maps geolocation autocomplete.
- Click Save Form.
Then geocode the existing entries again, as the next section shows.
Geocoding existing entries again #
An entry is looked up again once its saved position is deleted. With Enable automatic geocoding on in the Map View’s Maps settings, the map looks up those entries with your code the next time its page loads. Each page of the map looks up only the entries it shows.
One entry
- Go to Forms, then Entries, and click the entry to open it.
- Under the address, delete the numbers in the Latitude and Longitude boxes, and click the Update button next to them.
- Open the page with the Map View.

Every entry of a form
This WP-CLI command deletes the saved positions of one Address field for every entry of a form. Run it in a terminal, from your site’s WordPress folder. Replace 12 with the form’s ID and 3 with the Address field’s ID:
wp eval 'foreach ( GFAPI::get_entry_ids( 12 ) as $entry_id ) { foreach ( array( "lat", "long", "error" ) as $key ) { gform_delete_meta( $entry_id, "gvmaps_{$key}_3" ); } }'It also deletes positions you typed by hand and the marks of failed lookups. Then open each page of the Map View, so the map looks up the entries on every page.
Changing the address text #
gravityview/maps/marker/address receives the address after its parts are joined into one line, such as 1120 SW 5th Ave Portland, Oregon 97204 United States. GravityView Maps looks up the text the filter returns.
For example, a food bank in Oregon collects its volunteers’ addresses, and some volunteers leave the State / Province box empty. The address 225 5th St, Springfield, with no state, is looked up as Springfield, Illinois. This code adds the state to any address that doesn’t name it:
/**
* Adds ", Oregon" to the address GravityView Maps geocodes for one form,
* when the address doesn't name Oregon.
*
* @param string $address The address as one line of text.
* @param array $entry The entry.
* @param GF_Field $field The Address field, or the field set by gravityview/maps/markers/address/field_id.
*
* @return string The address to geocode.
*/
add_filter( 'gravityview/maps/marker/address', function ( $address, $entry, $field ) {
// Replace 12 with the ID of your form.
if ( 12 !== (int) rgar( $entry, 'form_id' ) ) {
return $address;
}
// Every address on this form is in Oregon, and some visitors leave the state out.
if ( false === stripos( $address, 'Oregon' ) ) {
$address .= ', Oregon';
}
return $address;
}, 10, 3 );Note: Adding custom PHP code snippets to your website shows where to put this code.
With the code, that address is looked up as 225 5th St Springfield United States, Oregon and its pin lands in Springfield, Oregon. Addresses that already name Oregon are looked up as they were.
To geocode a field that isn’t an Address field, see How can I pull the address from a field type that is not Address?. The developer reference lists every parameter of gravityview/maps/marker/field-value and gravityview/maps/marker/address.