It seems a pretty common use case that people would want to store addresses and show those addresses on a map.

The Address module seems to handle address storage very well.

Ideally it would be possible to use the Geolocation Google Geocoder to enter an address, then select a location, and populate the fields provided by the Address module.

There is a similar issue relating to the Drupal 7 version: #1040640: Store and display geocoded address information AND/OR address data entered by users and a D7 feature request for integration with addressfield: #2465337: Integrate Addressfield module

CommentFileSizeAuthor
#60 2681335-60-geocoding-handling.patch3.55 KBmstef
#59 2681335-59-geocoding-handling.patch3.74 KBmstef
#57 2681335-57-geocoding-handling.patch3.25 KBmstef
#56 2681335-56-geocoding-handling.patch2.52 KBmstef
#51 streetNumber_after_street.png226.43 KBNetNerdy
#43 2681335-43-geocoding-handling.patch29.98 KBChristianAdamski
#38 2681335-38-geocoding-handling.patch29.29 KBChristianAdamski
#33 2681335-33-geocoding-handling.patch0 bytesChristianAdamski
#32 2681335-32-geocoding-handling.patch26.88 KBChristianAdamski
#27 geolocation-integration_with_address-2681335-27.patch3.36 KBheddn
#19 screenshot.png25.54 KBNetNerdy
#18 interdiff_17-18.txt1.07 KBedysmp
#18 geolocation-integration_with_address-2681335-18.patch3.75 KBedysmp
#17 geolocation-integration_with_address-2681335-17.patch3.73 KBedysmp
#16 geolocation-integration_with_address-2681335-16.patch3.73 KBzerolab
#15 integration_with-2681335-15.patch3.67 KBpcambra
#4 integration_with-2681335-4.patch3.39 KBmalcomio
#2 integration_with-2681335-2.patch3.37 KBmalcomio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

malcomio created an issue. See original summary.

malcomio’s picture

I've made a start on this - it feels quite hacky, and there's a lot of scope for improvement, but it kind of works...

malcomio’s picture

The last submitted patch, 2: integration_with-2681335-2.patch, failed testing.

The last submitted patch, 2: integration_with-2681335-2.patch, failed testing.

The last submitted patch, 2: integration_with-2681335-2.patch, failed testing.

The last submitted patch, 2: integration_with-2681335-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: integration_with-2681335-4.patch, failed testing.

The last submitted patch, 4: integration_with-2681335-4.patch, failed testing.

The last submitted patch, 4: integration_with-2681335-4.patch, failed testing.

The last submitted patch, 4: integration_with-2681335-4.patch, failed testing.

malcomio’s picture

Status: Needs work » Needs review
derjochenmeyer’s picture

Great, thanks! Lets wait to get more eyes on this one.

pcambra’s picture

I've tested #4 and works great for my use case, but probably is a bit of a biased implementation.

I'm attaching a new patch that adds the lookup when positioning the marker.

We probably want to make this more generic and probably extensible by following something similar to #1040640: Store and display geocoded address information AND/OR address data entered by users and adding a setting in the geolocation field to match which address field (or any other module for that matter) should be updating.

I think this patch as it is will update every address field in the edit screen.

NetNerdy’s picture

FileSize
25.54 KB

hi, thank you very much for your nice works.

where can i set the "address" module as data-storage on geolocation field module? (see attached image)

i am working on localhost, drupal 8.1.1, php 7 and also the patch #18

thank's

The last submitted patch, 2: integration_with-2681335-2.patch, failed testing.

The last submitted patch, 4: integration_with-2681335-4.patch, failed testing.

The last submitted patch, 15: integration_with-2681335-15.patch, failed testing.

The last submitted patch, 16: geolocation-integration_with_address-2681335-16.patch, failed testing.

The last submitted patch, 17: geolocation-integration_with_address-2681335-17.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: geolocation-integration_with_address-2681335-18.patch, failed testing.

ChristianAdamski’s picture

This needs another re-roll. Anybody? :)

heddn’s picture

ChristianAdamski’s picture

Title: Integration with Address module » Dump address result from geocoder widget in address field
derjochenmeyer’s picture

What happens if Address Field is not present / installed?

Should there be any settings? Not that I think we need settings. Simplistic solutions are good. Didn't have a chance to test the patch but it looks nice and clean.

heddn’s picture

re #29: I thought about that when I was re-rolling this. I think what happens is the jquery selector fails to find address module's fields and doesn't insert them. One thing to consider is if there are multiple address module fields on the edit form. We could have a configuration to select which one. But I feel like that type of complexity can go into a follow-up. This gets ball rolling, is simple to review and we can add functionality later.

ChristianAdamski’s picture

I'm working on it :)

ChristianAdamski’s picture

- moved geocoding functionality to separate library
- added resultCallback() functionality to geocoder
- removed geocodingWidget specific code in geocoder
- wired up resultCallback in geolocation-widget-geocoder.js
- added settings to geocoding widget to select address field
- added handling of selected field to geolocation-widget-geocoder.js
- fixed 'controlls' typo
- fixed independent issue of map not loading in geocoding widget
- some minor issues

- TODO: preparation work is there, to store the address in a hidden form and save it in Drupal later. This would allow to completely hide the address field and still get it populated.

Please test.

ChristianAdamski’s picture

- Re-roll against HEAD
- fixed an issue where map would not load in geocoder widget on new content
- added a lot more JS documentation, drastically reducing ES Lint warnings

Status: Needs review » Needs work

The last submitted patch, 33: 2681335-33-geocoding-handling.patch, failed testing.

The last submitted patch, 33: 2681335-33-geocoding-handling.patch, failed testing.

The last submitted patch, 33: 2681335-33-geocoding-handling.patch, failed testing.

The last submitted patch, 33: 2681335-33-geocoding-handling.patch, failed testing.

ChristianAdamski’s picture

Status: Needs review » Needs work

The last submitted patch, 38: 2681335-38-geocoding-handling.patch, failed testing.

The last submitted patch, 38: 2681335-38-geocoding-handling.patch, failed testing.

The last submitted patch, 38: 2681335-38-geocoding-handling.patch, failed testing.

The last submitted patch, 38: 2681335-38-geocoding-handling.patch, failed testing.

ChristianAdamski’s picture

  • ChristianAdamski authored 9f64595 on 8.x-1.x
    Issue #2681335 by ChristianAdamski, edysmp, malcomio, heddn, pcambra,...
ChristianAdamski’s picture

Status: Needs review » Fixed

Committed. I think this is progress. Also allows some nicer handling of other issues.

NetNerdy’s picture

Component: User interface » Geolocation field
Status: Fixed » Needs work

@ChristianAdamski

the function doesn't work -> geolocation address-field doesn't take on the data from address-module (field_address).
working on localhost, Drupal 8.1.3, php 7, last geolocation-update 8.x-1.x-dev from July 27, 2013 - 10:34

when i add the address-data manually is anything fine -> but that's not the idea by this patch/function ;)

settings in content-type:
- address-module required and have this fields: addressLine1, postalCode, locality and country (only one country is available, e.g. Germany)
- Geolocation Google Geocoder -> Geocoded address will be stored in field_address

settings in address-module:
- Postal code type -> Postal Code
- Locality type -> City (also tested with Post town)

Set the Google API-key and all needed Google API's are enabled.

Whats wrong in my settings?

Thanks a lot for your help!

ChristianAdamski’s picture

@NerdyCrowd,

this is probably a mis-understanding. Right now this widget only works in one specific way:
when editing the content, there is the geolocation field present with geocoding widget AND the target address field defined in the geolocation widget settings is present with the default address widget.

Selecting an address in the geocoder widget should then set the values in the address widget.

That hidden form with address values you see there, is just part of a TODO. I would like to extend the functionality when I find time for that, but tight now that hidden form is entirely useless. Maybe I should remove it for now...

Does this help?

ChristianAdamski’s picture

Status: Needs work » Postponed (maintainer needs more info)
NetNerdy’s picture

@ChristianAdamski

Thank you very much for this explanation. So, there is - at the moment - no benefit for our users after implementing the geolocation field module.
we need address-data in two ways:
1. as description of a location, e.g. address from a building - this is seen for all users
2. as submission/data-value for maps - the map is seen for the users
in this case, our editors have to write "double" the address-data, right?

hmmm...ok...this is really a misunderstanding in this patch/extension.

Ok...now...perhaps...is there any way or idea to solve this problem?
the following could be a wonderful functionality (i think):
the data-value from the address-module will take over in the geolocation-module (address-field).
exists a planning in this direction?

...by the way...the leaflet-module give us a solution. leaflet take over the address-data from address-module to printing-out a map...but leaflet-maps are not so common and nice like google maps in geolocation-module...and...leaflet isn't under intense development like geolocation

;) ?

Thank's in advance!

dkre’s picture

@NerdyCrowd

I can't quite understand how this patch doesn't satisfy your needs.

If you have the geolocation pre-populate the address then there isn't any need for manual input into the address field.

-

@ChristianAdamski, This patch works really well - nice work. The only issue is it doesn't work for multi-value fields. I would perhaps document this limitation when this is commited.

NetNerdy’s picture

FileSize
226.43 KB

@ChristianAdamski...thank you very much for your work!!!

now, the geolocation field prepopulates the address field (address-module: address line 1, postal-code, locality).

When i mark the address (address-module) as required, then address fields will NOT prepopulating.

And...the (german) address-format isn't right after prepopulating. geolocation fills in "address line 1" at first the streetNumber and as second the street. the right way is 1. street, 2. streetNumber. I don't know if this managed by geolocation (autofill processing) or in address module. (see attachment)

Thanks for any help!

malcomio’s picture

@NerdyCrowd I think it would make sense to create a separate issue for the specific bug that you've observed.

NetNerdy’s picture

@ ChristianAdamski / malcomio
i have locate the one issue - (german) format in address line 1, in:

geolocation/js/geolocation-widget-googlegeocoder.js
line 166 - changed
from:
addressLine1 = streetNumber + ' ' + route;
to:
addressLine1 = route + ' ' + streetNumber;

but...the other issue (address as required) i haven't a solution...

I don't know "How to create a patch..." ...so i can write it here only.

mstef’s picture

Not working for me with latest dev. Searching via the geolocation field widget does not pre-populate the Address field (despite it being set in the form settings).

Actually, when I set a linked Address field in the form settings, I am no longer able to select an address in the Geolocation field.

Getting these:

Uncaught TypeError: Cannot read property 'replace' of undefined (line 126)

I think there's a disconnect in the JS settings:

// JS looks for it
var targetField = drupalSettings.geolocation.widgetSettings.addressFieldTarget;

// PHP sets it
$element['map_canvas']['#attached']['drupalSettings']['geolocation']['widgetSettings'][$canvas_id]['addressFieldTarget'] = $settings['target_address_field'];

JS is missing the $canvas_id

Changing the JS to: var targetField = drupalSettings.geolocation.widgetSettings[map.id].addressFieldTarget; clears the error, but the functionality still does not work.

mstef’s picture

Status: Postponed (maintainer needs more info) » Needs work

Continuing from above, in order to get the functionality to work, I remove the first and last two lines of:

              $(document).ajaxComplete(function (event, xhr, settings) {
                if (settings.extraData._drupal_ajax && settings.extraData._triggering_element_name === targetField + '[0][country_code]') {
                  var addressDetails = addressField.find('.details-wrapper').first();
                  // Populate the address fields, once they have been added to the DOM.
                  addressDetails.find('.organization').val(premise);
                  addressDetails.find('.address-line1').val(addressLine1);
                  addressDetails.find('.address-line2').val(addressLine2);
                  addressDetails.find('.locality').val(locality);
                  addressDetails.find('.administrative-area').val(countryCode + '-' + administrativeArea);
                  addressDetails.find('.postal-code').val(postalCode);
               }
             });

After that, the mapping is incorrect.

I had to change the administrative mapping to:

addressDetails.find('.administrative-area').val(countryCode + '-' + administrativeArea);

The city was also always being added to address 2. I had to remove the extra initial ! from: if (!!locality && locality !== postalTown) {

mstef’s picture

mstef’s picture

One more issue to fix.. Some places (like in NYC) do not return a locality/city but instead a neighborhood. This change will use that if there is no locality.

Also had to fix some logic that I mentioned above regarding the locality check.

mstef’s picture

Status: Needs work » Needs review
mstef’s picture

Actually I'm removing the assignment of locality to address2 completely. I can't see how that's helpful.

Also setting premise to address1 if there is no street or route. This may be another NYC thing..

mstef’s picture

Status: Needs review » Needs work

The last submitted patch, 60: 2681335-60-geocoding-handling.patch, failed testing.

ChristianAdamski’s picture

Hey mstef,

I altered the google geocoder widget to disconnect it more from the upcoming geocoder plugin stuff. Therefore your patch won't apply right now.

Can you re-apply your patch against current -dev and ensure it works as expected? I will then happily commit it.

ChristianAdamski’s picture

Fixed in #2835910: Google Geocoder Widget cleanup & extension

I incorporated most of @mstef and @NerdyCrowd's work there.

ChristianAdamski’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.