Hello,

Since the last alpha release, geofield provide a proximity filter for views.

It would be nice to have an autocomplete field for that exposed filter.

Basically the options should allow to choose what do you want to autocomplete (country, regions, city...) for the origin field.

What do you think about that ?

Regards,

Alex

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benjmarr’s picture

Great idea alex... would certainly use this for a Project we are working on!!

trebormc’s picture

good idea

fastangel’s picture

I did a patch for the integration. Now in the exposed filter (geocoder) you can select geocoder autcomplete.

fastangel’s picture

Status: Active » Needs review
fastangel’s picture

Sorry I did bad the patch. I attach new patch.

fastangel’s picture

Sorry a new patch again :(

benjmarr’s picture

Hi There,

Tried Patching but it failed at one of the points-

Last login: Tue Sep 10 17:15:07 on console
~ $ cd Sites/geocoder_autocomplete
geocoder_autocomplete $ patch -p1 < geocoder_autocomplete-integration_geocoder_views.patch
patching file geocoder_autocomplete.info
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file geocoder_autocomplete.info.rej
patching file geocoder_autocomplete.module
Hunk #1 succeeded at 60 with fuzz 2 (offset -27 lines).
patching file views/proximity_plugins/geofieldProximityGeocoderAutocomplete.inc
geocoder_autocomplete $

also where does it give you the option in views?

fastangel’s picture

The patch work fine for me with the branch 7.x-1.x. The patch implements a hook of geocoder. Then when you select a proximity filter you can select the origin point. In the origin point you have a new options. Autcomplete geocoder.

Regards.

edivad’s picture

It work also for me.
Geofield branch 2.X and geocoder 1.X.

Thanks.

joco_sp’s picture

wich worked for you?
I tried #6, but I can't apply it. It gave me the error: Hunk #1 FAILED at 1.
and saved the rejects in a file.

the rejects are these:
***************
*** 1,3 ****
name = Geocoder Autocomplete
description = Provides a text field widget with autocomplete via the Google Geocoding API.
core = 7.x
--- 1,4 ----
name = Geocoder Autocomplete
description = Provides a text field widget with autocomplete via the Google Geocoding API.
core = 7.x
+ files[] = views/proximity_plugins/geofieldProximityGeocoderAutocomplete.inc

MXT’s picture

I can confirm that patch provided in #6 works well for me.

I'm using Geofield branch 2.X and geocoder 1.X.

BUT PAY ATTENTION PLEASE: patch in #6 does not apply: I had to manually applying it.

Thank you very much: I hope this can be committed soon by maintainers

MXT’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Hide wrong patches, and marked as RTBTC because patch works correctly, although it must be manually applied

svanou’s picture

Hi all,
I cannot get it to work on my exposed filter. Can someone explain how to apply manually ?
Thanks, Sylvain

svanou’s picture

can someone point me in the right direction ?
Thanks!

Anonymous’s picture

The solution works for me when creating a node based view, on a search index view I can't seem to use this great feature.
If I would want to implement this on a indexed node from the search index, would this be possible and could you point me to information regarding the hook I'd have to use to get this to work?

Basically I'm looking into getting a search page to allow the user to enter a center and radius but still have facets available to filter further.
The whole thing should be powered by SOLR through the search api. Unfortunately I have seen so many modules and patches that I am wondering if I shouldn't be looking into custom code.

The search page allows for a radius to be hardcoded from a center point but I want them to be exposed like this module does in views.

narkoff’s picture

I have same issue as #15. Manually apply patch and create standard "Content" view that hits the Drupal database, and the autocomplete works on the Geofield field type.

However, if a Solr Search API view is created, the same Geofield field that is now indexed does not expose the "Source of Origin Point" drop down. So, "Geocoder Autocomplete" can not be selected and there's no autocomplete functionality.

My Solr Search API view works just fine directly typing into this Geofield proximity filter and using Geocoder to convert the entry to lat/lon coordinates. I am simply looking for a (Google?) autocomplete function for the text entry only. Any ideas on how to accomplish this?

pinkonomy’s picture

Can this work for Search api location to replace the address field with the Geo autocomplete?
thanks

pinkonomy’s picture

Any news on this?Is there any way to achieve this?

bluesman2014’s picture

I applied patch #6 but I can't get the Geo autocomplete to work. If I select 'Geocoder Autocomplete' as the Source of Origin Point in my exposed filter, it throws an AJAX HTTP 500 error at me:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: http://***.com/admin/structure/views/ajax/config-item/***/page/filter/field_geofield_distance
StatusText: Internal Server Error
ResponseText:  

And the error log tells me:

PHP Fatal error: Call to a member function value_validate() on a non-object in /home/***/public_html/sites/all/modules/geofield/views/handlers/geofield_handler_filter.inc on line 194

Has anyone else come across this?

capfive’s picture

patch applied fine for me on dev version, working perfectly! thanks so much!

Anonymous’s picture

@bluesman2014

I have the same error, did you figured this out?
I tried the same steps as you did, my ajax error code is 200 but the php log error is on the same line 197.

@capfive
can you elaborate how you got this working?

Pequi-eu’s picture

@bluesman2014
@pintoflager

Same Ajax Error code 500. Did you managed to fix it?

Thanks a lot!

imavers’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.5 KB

I've fixed a small issue in patch #6. There were a couple of params missing in

function geocoder_autocomplete_proximity_views_handlers()
Pequi-eu’s picture

Don't know what I did but patch is now working with no AJAX Error. I will try to investigate.

jarjar’s picture

#23 works for me. Thanks for the patch !

alves76’s picture

@Pequi-eu Have you figured out how to fix #19 ajax error?

alves76’s picture

Priority: Normal » Critical
alves76’s picture

Component: Documentation » User interface
MXT’s picture

#23 works for me also.

Please commit

MXT’s picture

It seems that

patch #23 does not work with Drupal version > 7.38

This probably due to autocomplete API changes in 7.39, see "known issue" in https://www.drupal.org/drupal-7.39-release-notes

Some other modules have already adapted their autocomplete logic. For reference:

Also always from https://www.drupal.org/drupal-7.39-release-notes:

There are a few changes to Drupal's autocomplete system that can affect custom or contributed modules which use the autocomplete system in an advanced way.

  1. There is a new form API #process function on autocomplete-enabled text fields that is required for the autocomplete functionality to work; custom and contributed modules should ensure that they are not overriding this #process function accidentally when altering text fields on forms (use element_info_property() for help with that).
  2. The above #process function uses the standard form API $element['#id'] property and assumes that it will match the actual ID that is output in the HTML. The form API normally takes care of this automatically, but if your form-building code is setting an explicit ID make sure that you are doing it via the correct/supported method, i.e. by setting $element['#id'] rather than $element['#attributes'][id']. See the form API documentation for #id and #attributes for more information.
  3. Part of the security fix also includes changes to theme_textfield(); it is recommended that sites which override this theme function make those changes as well (see the theme_textfield section of this diff for details).
  4. For security reasons, the autocomplete system now makes Ajax requests to non-clean URLs only, although protection is also in place for custom code that does so using clean URLs.
Pequi-eu’s picture

@alves76
I didn't understand what happened but I'm using 7.41 and #23 was not working at the beginning and then worked. I didn't have enough time to search and understand.

slaurent’s picture

Just tried this module with the patch and encountered the same error (ajax http 200, php fatal error detailed in #19). Any news on how to fix it? I'm using 7.41. Maybe it depends on Geofield version as well?

Maximus8’s picture

@slaurent
i read through the functions which where called by my view and they showed me that the Views Plugin was simply not in the right folder. I had to create a folder proximity_plugins in the views folder of geocoder_autocomplete and move the .inc file there. Now i dont have any AJAX error...maybe its also the solution in your cases!

But besides that i can choose now the geocoder autocomplete as source of origin point, i dont get any additional features. Am i missing something? i dont get a autocomplete Box, its still the normal geofield field...everything is just like before.

EDIT: I have figured out, that regarding the html classes the autocomplete_path attribute is not added by the after_build function. But altering other attributes like "required" works perfectly...I also tried to add the autocomplete_path on a custom form via the form api and it works! So theres just a problem in the geofield field widget with adding this behaviour. I have no idea what, but something is blocking the behaviour to be attached.

EDIT2: Regarding the questions in my contact formular, the description was not that clear, so the path where the .inc file should be is:
/sites/all/modules/geocoder_autocomplete/views/proximity_plugins/geofieldProximityGeocoderAutocomplete.inc

cp4w’s picture

Hello,

I applied the patch (#23). But the '#autocomplete_path' was not raised while entering text in the field.

But indeed (I've read this earlier in this discussion), since Drupal 7.39, the Autocomplete Ajax calls have to be validated first.

The patch adds this:

function geocoder_autocomplete_add_autocomplete_form($element) {
$element['origin']['#autocomplete_path'] = 'geocoder/autocomplete';
return $element;
}

Instead, the following is sovling the problem to me:

function geocoder_autocomplete_add_autocomplete_form($element) {
$element['origin']['#autocomplete_path'] = 'geocoder/autocomplete';

if (function_exists('form_process_autocomplete')) {
$element['origin'] = form_process_autocomplete($element['origin']);
}

return $element;
}

I've no much time to create a new patch... I'm just going to hack the contrib module (baaaaad I know.... :-) ). If someone wants to create a new patch... be my guest.

MXT’s picture

YES!, solution provided by cp4w in #34 seems to resolve the issue.

Thank you!

Waiting for a patch now :)

MXT’s picture

Ok I made a cumulative patch including #34: all works right for me now.

Please review it.

(patch created with git format-patch: should be applied with git am <patch-name>)

Thank you

EdPhillis’s picture

Could someone tell me how you apply one patch file in two different places??

donquixote’s picture

Code:
Just saying, there are whitespace errors.

Functionality:
I am trying this with Search API / Facet API, and Geofield with LatLong Pair (indexed).
So far I don't see how to enable the autocomplete for this.
The only options I see are the "Input method": Either "Geocoder input" or "Raw input".

EDIT:
This said, I also don't see how to apply any of the other proximity handlers from geofield_proximity_views_handlers().

EDIT:
I just hacked it myself with hook_form_views_exposed_form_alter(). Not really a solution for this issue, obviously.

GiorgosK’s picture

#36 patch did not apply cleanly with "git apply -v patchname.patch"

I applied it by hand which was not too difficult
but still enabling and using the view was bringing back a WSOD with no log messages in the system

I had no time to debug since it was extra functionality which can wait

kateryna16f’s picture

Hello,

patch from #36 almost working for me.
In the view preview mode the google addresses appears when I'm typing in the field.

In the frontend the autocomplete doesn't work. Any ideas?

jantoine’s picture

The attached patch fixes all coding standards issues with the patch from #36.

Note: The patch fails to apply to releases provided by Drupal, and that's OK. Patches are meant to be applied to the git repository, not to releases.

The patch fails to apply to releases due to a conflict with changes made by this patch and those made by Drupal's packaging system to the geocoder_autocomplete.info file. To work around this, remove and manually apply the first hunk in the patch to the geocoder_autocomplete.info file. The remainder of the patch should apply to the 1.1 or 1.x releases just fine.

If you find that autocomplete is working during views configuration but not in the frontend, this is caused due to lack of permission. The 'Access Geocoder Autocomplete' permission needs to be given to any roles you wish to be able to use the feature.

nessunluogo’s picture

Any luck to make this work with Search API?

PS: when I apply the patch the GeofieldProximityGeocoderAutocomplete.inc is added into views/proximity_plugins but into ip_geoloc module folder instead of geocoder_autocomplete. Moving the file in the right place makes it work perfectly. Anyone is getting this issue?

steffl’s picture

#41 is working for me, have two questions on that:

1)
The exposed filter is showing up in a views page but not in a views block. Is this normal or am i missing something?

2)
Autocomplete shows only 1 suggestion, normally it makes sense to show more. If the visitor only typed in 3 characters of the city, the one result showing up is mostly not the city the visitor is looking for. How can I achieve to show up 3 or 5 results?

benjmarr’s picture

Using patch #41.

Digging up an old issue but seem to be having some trouble. The filter works as in I can type in an address (google formatted) and return correct results but I cannot get the autocomplete to show results on both admin and front end. No errors that I can see in console or log.

Summit’s picture

Hi, has anybody this working please?
Thanks for your reply in advance.
greetings, Martijn

danzVP06’s picture

Hi,

I applied the patch number #41 but still not getting autocomplete, but then I found and applied this patch which gets the api key: https://www.drupal.org/project/geocoder/issues/2955244#comment-12807038

I can now see the autocomplete, it's only showing one result. but it's working on views page and views block exposed filter.

Hope this helps anybody

Summit’s picture

Hi, Can you may be show your view on which it is working please? thanks in advance!. Greetings, Martijn