Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment | File | Size | Author |
---|---|---|---|
#60 | 2681335-60-geocoding-handling.patch | 3.55 KB | mstef |
#59 | 2681335-59-geocoding-handling.patch | 3.74 KB | mstef |
#57 | 2681335-57-geocoding-handling.patch | 3.25 KB | mstef |
#56 | 2681335-56-geocoding-handling.patch | 2.52 KB | mstef |
#51 | streetNumber_after_street.png | 226.43 KB | NetNerdy |
Comments
Comment #2
malcomio CreditAttribution: malcomio commentedI've made a start on this - it feels quite hacky, and there's a lot of scope for improvement, but it kind of works...
Comment #3
malcomio CreditAttribution: malcomio at Capgemini commentedComment #4
malcomio CreditAttribution: malcomio at Capgemini commentedImproved the patch - if the locality matches the post town, don't duplicate them
Comment #13
malcomio CreditAttribution: malcomio at Capgemini commentedHEAD is also failing: https://www.drupal.org/node/241478/qa
Comment #14
derjochenmeyer CreditAttribution: derjochenmeyer at forward-media.de commentedGreat, thanks! Lets wait to get more eyes on this one.
Comment #15
pcambraI'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.
Comment #16
zerolab CreditAttribution: zerolab at Torchbox for Mencap commentedRe-roll for #15 to handle the yet to be initialized geocoder.
Comment #17
edysmpReroll for #16
Comment #18
edysmpAdded support for city and state.
Comment #19
NetNerdy CreditAttribution: NetNerdy commentedhi, 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
Comment #26
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedThis needs another re-roll. Anybody? :)
Comment #27
heddnReroll
Comment #28
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedComment #29
derjochenmeyer CreditAttribution: derjochenmeyer at forward-media.de commentedWhat 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.
Comment #30
heddnre #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.
Comment #31
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedI'm working on it :)
Comment #32
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commented- 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.
Comment #33
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commented- 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
Comment #38
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedOops, empty patch
Comment #43
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commented- missing schema added
Comment #45
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedCommitted. I think this is progress. Also allows some nicer handling of other issues.
Comment #46
NetNerdy CreditAttribution: NetNerdy commented@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!
Comment #47
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commented@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?
Comment #48
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedComment #49
NetNerdy CreditAttribution: NetNerdy commented@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!
Comment #50
dkre CreditAttribution: dkre commented@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.
Comment #51
NetNerdy CreditAttribution: NetNerdy commented@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!
Comment #52
malcomio CreditAttribution: malcomio at Capgemini commented@NerdyCrowd I think it would make sense to create a separate issue for the specific bug that you've observed.
Comment #53
NetNerdy CreditAttribution: NetNerdy commented@ 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.
Comment #54
mstef CreditAttribution: mstef commentedNot 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.
Comment #55
mstef CreditAttribution: mstef commentedContinuing from above, in order to get the functionality to work, I remove the first and last two lines of:
After that, the mapping is incorrect.
I had to change the administrative mapping to:
The city was also always being added to address 2. I had to remove the extra initial ! from: if (!!locality && locality !== postalTown) {
Comment #56
mstef CreditAttribution: mstef commentedPatch for the changes in 54 and 55.
Comment #57
mstef CreditAttribution: mstef commentedOne 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.
Comment #58
mstef CreditAttribution: mstef commentedComment #59
mstef CreditAttribution: mstef commentedActually 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..
Comment #60
mstef CreditAttribution: mstef commentedRemoved a console.log line.
Comment #62
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer commentedHey 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.
Comment #63
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer and at Wolters Kluwer commentedFixed in #2835910: Google Geocoder Widget cleanup & extension
I incorporated most of @mstef and @NerdyCrowd's work there.
Comment #64
ChristianAdamski CreditAttribution: ChristianAdamski as a volunteer and at Wolters Kluwer commented