Closed (fixed)
Project:
Geocoder
Version:
7.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Nov 2012 at 16:30 UTC
Updated:
26 Nov 2018 at 16:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
greenskunkYou can still choose coordinates using the OpenLayers, Geofield, Addressfield, Geocoder modules. Have you seen the video that is linked on the Geocoder project page http://vimeo.com/38558646 ?
Comment #2
rich.3po commentedI too am looking for this - google is inaccurate with many postcode lookups in the UK, and addresses in Ireland don't even have a postcode so they are often way off the mark
I didn't notice anything in that video that allows for geocode from address with lat/long fallback?
If i have time to do this properly i'll look to create a patch for this
Comment #3
rich.3po commentedHeres a first attempt at a patch to provide this functionality.
- It provides an option on the field config form to allow site admin to enable lat/long override as an option
- On the node (or whatever entity) form, the user can tick an 'override' checkbox which will expose the lat/long widget as a manual override. This uses the standard lat/long widget provided by geofield module.
- If the box is not checked, it falls back to using standard address geolocation
The patch probably needs re-rolling since i was unable to clone this project locally (not sure why..), so its generated straight off my project code.
Please can you review and consider rolling into the module? I can think of several projects i've worked on which would benefit from this
Cheers
Comment #4
rich.3po commentedSorry accidentally left a hard-coded field name in there.... i'll get another patch done
Comment #5
rich.3po commentednew patch:
Comment #6
rich.3po commentedUpdated patch attached.
Main points that need review:
1) I've added a new widget config setting ("latlng_override"). This settings won't exist for existing installations until the field form is re-saved, so ideally we need an update hook to roll this in.
2) I've not had a chance to test/review for multi-value fields, so this needs checking...
Comment #7
Dentorat commentedYou've got a couple more instances of hard coded fieldnames in geocoder_element_validate, they should be $element['#field_name']. I've also noticed that if i save the node with override unchecked, it's checked again on node edit and that inputting a 0 into one of the fields doesn't work (this is very unlikely in my case, but I was testing).
I can come back to this tomorrow and try to address those issues if I dont see a reply, but thank you very much for the patch!
Comment #8
Dentorat commentedI've updated it to genericize the remaining field names and I switched it to check rounding to 3 digits since the value in the db is stored as 6 total digits (rounded to 4 for longitudes < 100, rounded to 3 for longitudes >= 100).
I've created a patch based off of dev
This does not address the 0 value issue and I have not tested this for multivalue fields
Comment #9
rich.3po commentedNice one - my time is quite short the rest of this week but i'll try take a look at that "0" issue when i get a chance
Comment #10
artatac commentedI wondered if there was a similar patch available for the 7.2 branch
Comment #11
brylie commentedComment #12
simon georges commentedLet's keep the main version / status for the maintaining team (if any) to find them more easily.
Comment #13
larowlanThis adds a hard dependency on geofield - we need to update the info file (patch coming)
Comment #14
larowlanre-roll and fixes #13
Comment #15
simon georges commentedCould we eventually not introduce the dependency to geofield module?
Are there use cases where we would have geocoder without the geofield module?
Comment #16
joelpittet@Simon Georges not sure about the answers to your question but the idea behind this patch seems really good to have when geocoding doesn't give any or incorrect locations. Though I do agree it would be nice to not have the dependency.
I've changed out the !isset() for an empty() check because it is easier to read, nearly as fast, and should give FALSE results which !isset() will only deal with NULLs.
Also this is a re-roll because dev moved and the whitespace fixes are no longer allowing #14 to apply.
And I added a check to drush backfill, but not sure if that's a good idea or if it will work, need a guinue pig on that one.
Comment #17
joelpittetDoesn't quite work so well the fields for lat/lon that are trying to react on the checkbox may have changed.
The ones I have are rendering as hidden with field_location[und][geom][lat] as their name.
And I get a notice:
Notice: Undefined index: lat in geocoder_field_widget_form() (line 170 of /sites/all/modules/contrib/geocoder/geocoder.widget.inc).
Which is looking for $element['lat']['#default_value'].
Comment #18
cameron prince commentedHere's an updated patch with a few tweaks to get the feature working and error-free. There is still a bug with the states function that I haven't solved yet. When editing a node with a geofield, the lat/long fields are visible all the time, regardless of the override checkbox. Unchecking the checkbox does cause the values to be reverted back to the look-up and it now remains unchecked when saved. It just doesn't hide the fields.
Comment #19
GoempieK commentedDid you get this to work?
I need the exact same thing, have a lot of adreses that are gaspumps near the freeway with no exact adres.
Comment #20
jibranHere is the interdiff from 16 and 18.
Comment #21
jibranI have added language and multivalue support to the patch and also added
hook_field_attach_loadto persist thegeocoder_overriddenon node load. This works nicely with workbench modration.Edit: I have also fixed the states issue with lat lon textfields.
Comment #22
larowlanwhitespace issue?
Good idea
nit: missing doc blocks
c/p error? no images here
This should hit the cache in geocoder_cache_get() so shouldn't be that expensive
Comment #23
jibranI found a bug while testing it locally so added a fixed for that also addressed #22. Thanks @larowlan for the review.
Comment #24
jibranc/p error once again fixed now.
Comment #25
jibranFound another minor issue.
Comment #26
broonVery useful extension of the module and exactly what I needed. I applied the patch from #25 to 7.x-1.3 manually in an existing site and it works w/o flaws. Nice job!
Comment #27
autopoietic commentedConfirm tested and seems to work well, though the hiding of the lat/lon form element until override is checked (via #state) does not work in my example (may be to do with some custom form_altering).
One other issue, which may be as designed, is that if a location has failed to geocode, and there is therefore no location stored, when it is overridden the manually determined location works as expected, but when the override is unchecked, the location remains unless the content of the manual lat/lon fields is deleted.
Comment #28
bessone commentedTested on last 7.x-1.x-dev, i have this error in node form:
Notice: Undefined index: lat in geocoder_field_widget_form() (linea 199 di /sites/all/modules/geocoder/geocoder.widget.inc).Comment #29
DevJoshLopez commentedI also applied the patch from #25 to 7.x-1.3 manually in an existing site and it works but getting this error:
Notice: Undefined index: lat in geocoder_field_widget_form() (line 199 of /home/moonbots2017/public_html/sites/all/modules/geocoder/geocoder.widget.inc).
Comment #30
DevJoshLopez commented.
Comment #31
jibranJust needs isset check here.
Comment #32
DevJoshLopez commentedThank you Jibran. Where does that code go? Doing this manually. Does it go below this?
Comment #33
letrotteur commentedGot the lat notice too and found out that lat and lon is stored under $element['geom']['#default_value']['lat'] instead of $element['lat']['#default_value'] in my project.
Comment #34
letrotteur commentedMade a patch based on my previous comment (geom instead of lat and lon) And added some logic for cases where we would want to override empty value (geocoded didnt returned anything or we only want to enter value manually.
Comment #35
Anonymous (not verified) commentedgeocoder-fallback-geocoding-1844840-34.patch worked for my site. I installed the Geocoder 7.x-1.x-dev - to get the most up to date, applied the patch - manually, and I got the one address marker that was about 5 miles off target to be right on.
Thanks for the great work!
Comment #36
jafacakes2011 commentedI have a content type that is set up with a location field set to Geocode from an address field. On existing nodes with Geocoded data this works fine. However, When I make a new node the geocode fields remain empty.
I managed to fix this issue by going into the field setting and checking: Allow manual lat/long override. With that enabled, when I make a new node with an address, the geocoded field works as I expect. I'm not sure why, but it seems that no request is being sent when the Allow override is disabled.
I am running the patch from #34, and that has fixed the other issue I had with the Override option always being set to TRUE.
Comment #37
jibranSo #25 is for geofield 7.x-1.x and #34 for 7.x-2.x here is a interdiff between two patches.
Comment #38
jibranFixed some CS issue with #34 and added a condition to info file.
Note: This patch works with geofield 2.x branch.
Comment #39
jibranHere is a reroll and #25 with the version check.
Comment #40
polHi,
What is the status of this patch ?
Thanks.
Comment #41
jibranPatch from #25 has already has been RTBC in #26. It works well with geofield 7.x-1.x and #39 is just a reroll of that.
Patch form #38 is for geofield 7.x-2.x and in #35 it is reported to be working fine.
Comment #42
polOk committed to 7.x-1.x.
Comment #44
polComment #45
jibranThanks for the commit. Can we commit #38 to 2.x branch?
Comment #47
Anonymous (not verified) commentedHi,
What was the reason for implementing the presave function in patch #39 (see
geocoder_field_attach_presave)? because the logic is wrong when this is used at a new node. It does the following check:if ($instance['widget']['type'] === 'geocoder'&& !empty($entity->{$field_name}) && ($geocoded_value = geocoder_widget_get_field_value($entity_type, $instance, $entity))) { .. }which won't work because$entity->{$field_name}is empty in a new node, hence the fact that!empty($entity->{$field_name})will always returnFALSE. If you would remove this then it still doesn't work because inside the if-statement it loops over the fieldforeach ($entity->{$field_name} as $langcode => $items) { ... }which doesn't work as well because as I said this field is empty initially, so the actual values will never be set on a new node.If I go back to v1.3 I see it does check if the field value is
FALSEinstead ofempty()which does work. Is there a reason why this function has been built like this? Because now I am never able to use geocoder v1.4 in new projects where there's no content.The setup I use is an address field + geofield, where the geofield is set to the address field by setting the widget "Geocode from another field".
If someone could fix this and at least explain the actual purpose of this, that'd be great.
- Thanks.