Populate Inputs with Latitude and Longitude

Instructions

  1. Install our free Custom JavaScript for Gravity Forms plugin.
     Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    
    1. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
    2. Update the selectors below to match the field IDs that will be populated with lat/lng.

Code

Filename: gpaa-populate-inputs-with-lat-lng.js

/**
 * Gravity Perks // GP Address Autocomplete // Populate Inputs with Latitude and Longitude
 * https://gravitywiz.com/documentation/gravity-forms-address-autocomplete
 *
 * Instructions:
 *     1. Install our free Custom JavaScript for Gravity Forms plugin.
 *         Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 *     3. Update the selectors below to match the field IDs that will be populated with lat/lng.
 */
window.gform.addAction('gpaa_fields_filled', (place) => {
	$('#input_GFFORMID_3').val(place.geometry.location.lat());
	$('#input_GFFORMID_4').val(place.geometry.location.lng());
});

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.