diff --git a/README.md b/README.md index 1018f06..a055dad 100644 --- a/README.md +++ b/README.md @@ -108,22 +108,15 @@ With Gravity Forms installed, you can install this plugin in the usual WordPress ### Creating your first Geocoding field -1. (Optional) Visit the Gravity Forms settings page enter a Geocod.io or -Google Maps API key, or to change which email is sent with OSM Nominatim API calls. +1. (Optional) Visit the Gravity Forms settings page enter a Geocod.io or Google Maps API key, or to change which email is sent with OSM Nominatim API calls. 2. Create a new Gravity Form (or edit an existing one). -3. (Optional) Visit the form settings page and select which geocoder to use. -It will use OSM Nominatim by default. +3. (Optional) Visit the form settings page and select which geocoder to use. It will use OSM Nominatim by default. 4. Add the input fields you want the user to fill out. 5. Add the Geocoder field (under the Advanced Fields tab). -6. In the Geocoder field associate the geocoder parameters with the other input -fields on your form. -7. Publish your form and add it to a page like you would any other Gravity -Form! - -and add the Geocoder field from the Advanced Fields -menu. Add other input fields, then in the Geocoder settings select which -fields will be used as parameters for the geocoding. - +6. In the Geocoder field associate the geocoder parameters with the other input fields on your form. +7. Publish your form and add it to a page like you would any other Gravity Form! +8. Add the non-Geocoding input fields. +9. Add the Geocoder field from the Advanced Fields menu and in the field settings select which fields will be used as parameters for the geocoding. Frequently Asked Questions -------------------------- @@ -151,17 +144,27 @@ If you create users or posts, and set a meta value to the value of a Brilliant Geocoder field, that value will be stored as spatial metadata. Brilliant Geocoder for Gravity Forms uses WP-GeoMeta internally. For sample -queries, please see the [WP-GeoMeta documentation](https://github.com/cimburadotcom/wp-geometa#querying). +queries, please see the [WP-GeoMeta documentation](https://github.com/brillliantplugins/wp-geometa#querying). ### Where can I get help with GIS and WordPress? For commercial support you can contact the plugin developer at -[Cimbura.com](https://cimbura.com/contact-us/project-request-form/) +[luminfire.com](https://luminfire.com/contact-us/project-request-form/) For fast and short questions you can [contact me](https://twitter.com/stuporglue) on twitter. Changelog --------- += 0.0.3 = +* Improved Handling of Google Maps API +* Added support for Gravity Forms v2.4+ + += 0.0.2 = +* Updated wp-geometa-lib. +* Updated readme documentation. +* Tested with WP 4.8 +* Some additional debugging code. +* Fixed Google Geocoder. = 0.0.1 = * Initial release! diff --git a/brilliant-geocoder-gravityforms.php b/brilliant-geocoder-gravityforms.php index 92804c4..3ec8b6f 100644 --- a/brilliant-geocoder-gravityforms.php +++ b/brilliant-geocoder-gravityforms.php @@ -32,6 +32,7 @@ function geocoder_for_gf_init() { require_once( __DIR__ . '/lib/class-geocoder-gravity-settings.php' ); require_once( __DIR__ . '/lib/class-geocoder-gravity-field.php' ); + $wpgm_loader = __DIR__ . '/lib/wp-geometa-lib/wp-geometa-lib-loader.php'; if ( !file_exists( $wpgm_loader ) ) { error_log( __( "Could not load wp-geometa-lib. You probably cloned wp-geometa from git and didn't check out submodules!", 'brilliant-geocoder-gravityforms' ) ); diff --git a/geocoders/google_maps_api.js b/geocoders/google_maps_api.js index 34b5880..1436a20 100644 --- a/geocoders/google_maps_api.js +++ b/geocoders/google_maps_api.js @@ -1,18 +1,34 @@ window.gfg_geocoder_engines.google_maps_api = function( args, success_callback, failure_callback ) { + var params = {}; + var address = []; + var key = ''; + + // Split the address and the key into their own parameters + jQuery.each(args, function( index, value ){ + if ( index != 'key' ) { + address.push(value); + } else { + key = value; + } + }) + + address = address.join(' '); + params.address = address; + params.key = key // Make an API call and call the appropriate callback function. - jQuery.get('https://maps.googleapis.com/maps/api/geocode/json?' + jQuery.param( args ), function( success ) { + jQuery.get('https://maps.googleapis.com/maps/api/geocode/json?' + jQuery.param( params ), function( success ) { if ( success.status !== 'OK' ) { failure_callback( success ); return; } - + var geojson = ''; if ( success.results.length > 0 ) { var res = success.results[0]; - + // Build a GeoJSON object. geojson = { 'type': 'Feature', diff --git a/geocoders/google_maps_api.php b/geocoders/google_maps_api.php index cf90013..4b9f8d7 100644 --- a/geocoders/google_maps_api.php +++ b/geocoders/google_maps_api.php @@ -9,7 +9,12 @@ function gfg_gmapi_fields( $fields ) { $fields['Google Maps API'] = array( - 'address' => 'Search Field', + 'street' => 'Street', + 'city' => 'City', + 'county' => 'County', + 'state' => 'State', + 'postalcode' => 'Postal Code', + 'countrycode' => 'ISO 3166-1alpha2 Country Code', ); return $fields; @@ -37,7 +42,7 @@ function gfg_gmapi_keys( $keys, $geocoding_engine, $form ) { // Since the geocodio engine is in use, enqueue the file $base_url = plugins_url( '', dirname( __FILE__ ) ); - wp_enqueue_script( 'geocoder_geocodio', $base_url . '/geocoders/google_maps_api.js', array( 'gfg_geocode' ), filemtime( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'google_maps_api.js' ) ); + wp_enqueue_script( 'geocoder_googlemaps', $base_url . '/geocoders/google_maps_api.js', array( 'gfg_geocode' ), filemtime( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'google_maps_api.js' ) ); $gfg = Geocoder_for_Gravity::get_instance(); $settings = $gfg->get_plugin_settings(); diff --git a/lib/class-geocoder-gravity-field.php b/lib/class-geocoder-gravity-field.php index bab6cba..104dc32 100644 --- a/lib/class-geocoder-gravity-field.php +++ b/lib/class-geocoder-gravity-field.php @@ -110,6 +110,8 @@ public function get_field_input( $form, $value = '', $entry = null ) { $is_form_editor = $this->is_form_editor(); $logic_event = version_compare( GFForms::$version, '2.4-beta-1', '<' ) ? $this->get_conditional_logic_event( 'keyup' ) : ''; + $tabindex = $this->get_tabindex(); + $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || 0 === $form_id ? "input_$id" : 'input_' . $form_id . "_$id"; @@ -284,7 +286,7 @@ public function gform_field_standard_settings( $position, $form_id ) { print '
  • '; print ''; - print '

    Configure the mapping for the ' . esc_html( $which_geocoder ) . ' eocoding service.

    '; + print '

    Configure the mapping for the ' . esc_html( $which_geocoder ) . ' geocoding service.

    '; print ''; print ''; @@ -438,7 +440,6 @@ public function get_geocoder_field_mapping() { 'city' => 'City', 'county' => 'County', 'state' => 'State', - 'country' => 'Country', 'postalcode' => 'Postal Code', 'countrycode' => 'ISO 3166-1alpha2 Country Code', ), diff --git a/lib/class-geocoder-gravity-settings.php b/lib/class-geocoder-gravity-settings.php index c266c0f..d7d81f9 100644 --- a/lib/class-geocoder-gravity-settings.php +++ b/lib/class-geocoder-gravity-settings.php @@ -114,10 +114,6 @@ public function get_geocoders() { $geocoders = apply_filters( 'gfg_geocoders', $geocoders ); - if ( !is_array( $geocoders ) || empty( $geocoders ) ) { - error_log("The list of geocoders is empty! It wasn't empty before applying the gfg_geocoders filter."); - } - return $geocoders; } @@ -224,11 +220,12 @@ public function gform_form_settings( $settings, $form ) { // See which geocoder we're using. Default to the OSM Nominatim geocoder. $selected_geocoder = rgar( $form, 'which_geocoder' ); - $selected_geocoder = ( empty( $selected_geocoder ) ? 'OSM Nominatim simple query' : $selected_geocoder ); - + $selected_geocoder = empty( $selected_geocoder ) ? 'OSM Nominatim simple query' : $selected_geocoder ; + // Build up the options. $options = array(); $geocoders = $this->get_geocoders(); + foreach ( $geocoders as $geocoder ) { // Check if we have the required keys for the service. @@ -249,14 +246,14 @@ public function gform_form_settings( $settings, $form ) { } ksort( $options ); - + // Make the settings string. - $setting = ''; $settings['Geocoder']['which_geocoder'] = $setting; - + return $settings; } diff --git a/media/form_geocode.js b/media/form_geocode.js index 826c2be..d0d0f12 100644 --- a/media/form_geocode.js +++ b/media/form_geocode.js @@ -18,6 +18,7 @@ function gfg_update_geocoder( e ) { jQuery('#' + target_geocode_field).val(success); jQuery('#' + target_geocode_field).trigger('change'); + }; @@ -30,7 +31,7 @@ function gfg_update_geocoder( e ) { update_me.push( gc ); } } - + var curgc; // current geocoder var target_geocode_field; // the results field var fields; // dict of all source IDs and their cooresponding keys in the geocode request @@ -93,7 +94,7 @@ window.gfg_geocoder_engines = { ], } }; - + delete res.boundingbox; var props = res.extratags || {}; delete res.extratags; @@ -125,7 +126,7 @@ window.gfg_sync_data = function( field_id ){ this.init = function(){ this.field_id = field_id; - this.mapobj = window.leafletphp.maps['geocode_map_' + field_id]; + this.mapobj = window['geocode_map_' + field_id]; this.lat = jQuery('#' + field_id + '_lat'); this.lng = jQuery('#' + field_id + '_lng'); this.geojson = jQuery('#' + field_id); diff --git a/readme.txt b/readme.txt index 2eb5d31..e0d56b6 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Brilliant Geocoder for Gravity Forms === Contributors: stuporglue, luminfire, cimburacom Tags: Gravity Forms, GIS, geo, Spatial, geocoding, WP-GeoMeta, OSM, Nominatim, Google, Maps API, map, GeoJSON -Tested up to: 4.8 +Tested up to: 5.2.2 Requires at least: 4.4.1 -Stable tag: 0.0.2 +Stable tag: 0.0.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -11,26 +11,42 @@ Capture location information in Gravity Forms by geocoding user's input into oth == Description == -Brilliant Geocoder for Gravity Forms is a powerful and flexible geocoder field for Gravity Forms. The Geocoder field is easily be configured to capture geocoder input values from other form fields. +Brilliant Geocoder for Gravity Forms is a powerful and flexible geocoder field +for Gravity Forms. The Geocoder field is easily be configured to capture geocoder +input values from other form fields. -It comes with the [OSM Nominatim](http://wiki.openstreetmap.org/wiki/Nominatim) geocoder enabled by default and supports [Geocod.io](https://geocod.io/) and the [Google Maps API](https://developers.google.com/maps/) once you've entered API keys for those services. +It comes with the [OSM Nominatim](http://wiki.openstreetmap.org/wiki/Nominatim) +geocoder enabled by default and supports [Geocod.io](https://geocod.io/) +and the [Google Maps API](https://developers.google.com/maps/) once you've entered +API keys for those services. -The geocoder field can be displayed as a map, as latitude and longitude fields, as the raw GeoJSON data, or hidden. +The geocoder field can be displayed as a map, as latitude and longitude +fields, as the raw GeoJSON data, or hidden. -This plugin supports WP-GeoMeta, so if you create posts or users with geocoded data, their location will be stored as spatial metadata. +This plugin supports WP-GeoMeta, so if you create posts or users with geocoded +data, their location will be stored as spatial metadata. -**NOTICE**: _This plugin uses 3rd party services to provide geocoding results. The default geocoder, OSM Nominatim, requests that you include your email address in API calls if you are making a large number of requests. We send the WP admin email address by default. You can change what is sent on the Gravity Forms settings page, under *Geocoder*._. +**NOTICE**: _This plugin uses 3rd party services to provide geocoding results. +The default geocoder, OSM Nominatim, requests that you include your email address +in API calls if you are making a large number of requests. We send the WP admin +email address by default. You can change what is sent on the Gravity Forms settings +page, under *Geocoder*._. = What is Geocoding? = -[Geocoding](https://en.wikipedia.org/wiki/Geocoding) is the process of turning text (an address) into coordinates (latitude and longitude). With coordinates you can display data on a map and do location based searching. +[Geocoding](https://en.wikipedia.org/wiki/Geocoding) is the process of turning +text (an address) into coordinates (latitude and longitude). With coordinates +you can display data on a map and do location based searching. = Support for Other Geocoders = -Brilliant Geocoders for Gravity Forms includes hooks so that you can add support for other geocoding services. +Brilliant Geocoders for Gravity Forms includes hooks so that you can add +support for other geocoding services. -OSM Nominatim support is built into the plugin, but Geocod.io and Google Maps API support is written the same way that you would add support for another service. The Geocod.io example in particular has extensive comments. +OSM Nominatim support is built into the plugin, but Geocod.io and Google Maps +API support is written the same way that you would add support for another +service. The Geocod.io example in particular has extensive comments. Please see geocoders/geocodio.php and geocoders/geocodio.js for details. @@ -41,20 +57,28 @@ Be sure that Gravity Forms 2.0.0 or higher is installed. With Gravity Forms installed, you can install this plugin in the usual WordPress way. -1. Unzip and upload the plugin files to the `/wp-content/plugins/brilliant-geocoder-gravityforms` directory, or upload the plugin's .zip file through the WordPress plugin screen directly. +1. Unzip and upload the plugin files to the `/wp-content/plugins/brilliant-geocoder-gravityforms` directory, + or upload the plugin's .zip file through the WordPress plugin screen directly. 2. Activate the plugin on the 'Plugins' screen in WordPress. = Creating your first Geocoding field = -1. (Optional) Visit the Gravity Forms settings page enter a Geocod.io or Google Maps API key, or to change which email is sent with OSM Nominatim API calls. +1. (Optional) Visit the Gravity Forms settings page enter a Geocod.io or +Google Maps API key, or to change which email is sent with OSM Nominatim API calls. 2. Create a new Gravity Form (or edit an existing one). -3. (Optional) Visit the form settings page and select which geocoder to use. It will use OSM Nominatim by default. +3. (Optional) Visit the form settings page and select which geocoder to use. +It will use OSM Nominatim by default. 4. Add the input fields you want the user to fill out. 5. Add the Geocoder field (under the Advanced Fields tab). -6. In the Geocoder field associate the geocoder parameters with the other input fields on your form. -7. Publish your form and add it to a page like you would any other Gravity Form! -8. Add the non-Geocoding input fields. -9. Add the Geocoder field from the Advanced Fields menu and in the field settings select which fields will be used as parameters for the geocoding. +6. In the Geocoder field associate the geocoder parameters with the other input +fields on your form. +7. Publish your form and add it to a page like you would any other Gravity +Form! + +and add the Geocoder field from the Advanced Fields +menu. Add other input fields, then in the Geocoder settings select which +fields will be used as parameters for the geocoding. + == Frequently Asked Questions == @@ -65,22 +89,29 @@ With Gravity Forms installed, you can install this plugin in the usual WordPress = What data is sent to the geocoding service when I geocode? = -Whatever fields you select as a geocoding source in Gravity Forms will be sent to the geocoding service. This would typically means that address details entered into the form will be sent to the geocoding service for processing. +Whatever fields you select as a geocoding source in Gravity Forms will be sent +to the geocoding service. This would typically means that address details +entered into the form will be sent to the geocoding service for processing. -Your API key and/or any other parameters required by the service's terms of service will also be sent. +Your API key and/or any other parameters required by the service's terms of service +will also be sent. -Please review the Terms of Service of the service you select for details on how your submitted data is stored or used. +Please review the Terms of Service of the service you select for details on +how your submitted data is stored or used. = How can I run spatial queries? = -If you create users or posts, and set a meta value to the value of a Brilliant Geocoder field, that value will be stored as spatial metadata. +If you create users or posts, and set a meta value to the value of a Brilliant +Geocoder field, that value will be stored as spatial metadata. -Brilliant Geocoder for Gravity Forms uses WP-GeoMeta internally. For sample queries, please see the [WP-GeoMeta documentation](https://github.com/cimburadotcom/wp-geometa#querying). +Brilliant Geocoder for Gravity Forms uses WP-GeoMeta internally. For sample +queries, please see the [WP-GeoMeta documentation](https://github.com/cimburadotcom/wp-geometa#querying). = Where can I get help with GIS and WordPress? = -For commercial support you can contact the plugin developer at [Cimbura.com](https://cimbura.com/contact-us/project-request-form/) +For commercial support you can contact the plugin developer at +[Cimbura.com](https://cimbura.com/contact-us/project-request-form/) For fast and short questions you can [contact me](https://twitter.com/stuporglue) on twitter. @@ -101,13 +132,6 @@ For fast and short questions you can [contact me](https://twitter.com/stuporglue == Changelog == -= 0.0.2 = -* Updated wp-geometa-lib. -* Updated readme documentation. -* Tested with WP 4.8 -* Some additional debugging code. -* Fixed Google Geocoder. - = 0.0.1 = * Initial release! * Support for OSM Nominatim @@ -118,5 +142,6 @@ For fast and short questions you can [contact me](https://twitter.com/stuporglue == Upgrade Notice == = 0.0.1 = -* You don't have Brilliant Geocoder for Gravity Forms yet, so there's no need to read this upgrade notice! +* You don't have Brilliant Geocoder for Gravity Forms yet, so there's no need to read this upgrade +notice!