Howdy,

similarly to what was asked for 5.x at http://drupal.org/node/137405 , it's important IMO to have autocomplete work also for City field, as this would cut down on confusion, duplicates and input time.

There's a patch in the mentioned issue, but it does not apply to 6.x, or at list i couldn't find the City handler anywhere ['#title' => t('City') ]. Can anyone give a hint please? many thanks in advance

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

Issue tags: +location auto-complete

What kind of work flow are you thinking?

I'm thinking to be useful it would be: users enter country first, then state, then an auto-complete city value.

Or were you thinking of something else?

Tagging.

Roberto Gerola’s picture

Hi.

I developed a patch for this.
The development has been sponsored by Marco.

Roberto

YesCT’s picture

Status: Active » Needs review
YesCT’s picture

BWPanda’s picture

Applied patch, but cannot work out how it's supposed to work... The city field doesn't turn into an autocomplete field automatically, am I supposed to do something to activate it?

marcoBauli’s picture

@BWPanda: you need to fill in the list of the cities of your country in /location/supported/location.COUNTRY.inc with the following function:

function location_city_list_it() {
  return array(
                "Acciano,AQ" => "Acciano,AQ",
                "Aielli,AQ" => "Aielli,AQ",
                "Alfedena,AQ" => "Alfedena,AQ",
                "Anversa degli Abruzzi,AQ" => "Anversa degli Abruzzi,AQ",
                ...
  );
}
BWPanda’s picture

Ah, I didn't realise that was how it was going to work...
I figured since there are are so many more cities around the world than countries or provinces, that to save admins having to enter all cities initially, it could work similarly to the autocomplete taxonomy - users start typing a city, if it exists, it appears in a drop-down list to select from, if not, they finish typing it and it's added to the list of available cities for future.

Would this not be a better implementation, considering the number of cities around the world...? (I need world-wide cities, not just Australian ones)

Xabi’s picture

Cities names are included in the postal code databases, why to re-enter them again?

artatac’s picture

subscribing

YesCT’s picture

Issue tags: +location bdragon check

tagging

andrewsuth’s picture

+1 for this feature to be added

marcoBauli’s picture

@Xabi: you mean zipcodes.country.mysql? there are no city names there, only coordinates.. ?

goron’s picture

subscribing

juicytoo’s picture

Hi,

Is this somehow related to

http://drupal.org/project/geonames

cheers
Ed

sbydrupal’s picture

Applied the patch. However, in my case, does not seem to autocomplete. Tried to use Cities from Italy as this was included in the patch.

Any information if any body else applied this patch and checked for Cities in Italy as example?

Thanks

webanalya’s picture

Hi,

Does this patch work with location_cck or only with location_node ?

Thanks !

Summit’s picture

subscribing greetings, Martijn

sandino’s picture

subscribing

vlooivlerke’s picture

+1 for feature request, but use the zipcode database as it does contain city names.
And how about placing the marker on the city wile still on node creation page, rater than submitting the node first to see the geocoded location.

juicytoo’s picture

there is city names in the file

zipcodes.us.mysql

and

zipcodes.au.mysql

There is a field available for it.

The structure of the zipcodes contains country, city, postcode.

This might be inefficient.

If a user selects
- country first
- system should filter only the cities related to that country.

It might need a seperate table to store the country and then a table to reference the city/postcode.

Alan D.’s picture

Going all the way back to the patch in #2, we are getting a function not found fatal error. ( version 3.0 ) A quick fix was to alter the menu callback to include "location.inc", or this could be added to the menu callback function. (Menu appears cleaner)

<?php
  $items['location/autocomplete_city'] = array(
    'access arguments' => array('access content'),
    'page callback' => '_location_autocomplete_city',
    'file' => 'location.inc',
    'type' => MENU_CALLBACK,
  );
?>
Alan D.’s picture

FileSize
5.41 KB

I was getting too many issues with the 6.x-3.0 version, so I upgraded to the dev version, looking better :), and reapplied the patch without the .it cities (it is cleaner to review this way).

This is a great addition, but linking to states would be the next logical step, but adds a layer of complexity.

Cyberwolf’s picture

Subscribing

jcolby1028’s picture

Subscribing

khan2ims’s picture

The patch is not working on my 6.x-3.1-rc1 installation.

Alan D.’s picture

The patch was against a recent development version in CVS. I do not know what happened to the 3.1 branch, but it is not being shown anymore. Try the older patch, no new functionality was added in #21 (removed .it city data to keep the patch cleaner), it was just an updated patch to match the new 6.x-3.0 dev code

PieterDC’s picture

Applying the patch is not sufficient for it to work. You also need to provide a location_city_list_xx() for each country you provide. Take a look at the older patch, (in #2) Alan D. is talking about, to see how it's done.

@Alan: if you'd put the Italian cities in the zipcodes table, the patch could provide a general function getting all cities per country, instead of putting them in a hard-coded array in every country specific file, and thus eliminating the requirement of a location_city_list_xx() for each country. Or am I missing something? Just thinking.

Alan D.’s picture

This seemed like two issues - fix the bug & Italy data inclusion. Having one makes it easier to get the bug fix committed without having to wait for the feature request to get processed. I do not have the working knowledge of the module to comment any more sorry.

khan2ims’s picture

Hi,

Now the auto complete is showing up. But the location is not getting saved (although the form gets submitted) and hence location doen't show up on profile page.

Please check http://art.newearthmarketing.com/users/admin

Edit: I redid everything, and its working now :)

colan’s picture

Status: Needs review » Needs work

You shouldn't have to add any "location_city_list_xx()" function. As stated previously, this is redundant information that already exists in the zipcodes table.

colan’s picture

Status: Needs work » Needs review
FileSize
5.09 KB

This patch grabs city information from the zipcodes table.

hz_i3’s picture

subscribing

PieterDC’s picture

@colan: good thinking!

YesCT’s picture

Status: Needs review » Needs work

Powered by Dreditor.

+++ b/location_autocomplete.js
@@ -31,4 +31,31 @@ Drupal.behaviors.location = function(context) {
+  }).addClass('location-processed');  ¶

Extra space at the end of the line.

My first time using Dreditor... not a functional review. :) That is still needed.

clashar’s picture

subscribe

timos’s picture

subscribe

timos’s picture

@colan
Sorry for this newbies' question, but on witch files i have to apply the patch.
I try on location.inc, location_autocomplte.js and location.module, but it worked only on the two first files and not on the location.module file (maybe because i use the 6.x-3.-dev)

An another question : is this patch independant from other patches (#2 and #22 posts) ?

Thanks

Timos

timos’s picture

@colan
Well i apply your patch on the location.module file of a 6.x-3.0 version and it works correctly (make dif on location.module, location.inc and location_autocomplete.js).

So, after that, i tried it with the belgium cities (i dump the zipcode.be.mysql file in my database) and i could observe somes issues i report here to help you :

I had a location register in US : when i edited it and i select belgium in the country field, the city autocompletion was staying on the us
in firebug console the get url was location/autocomplete_city/us/.. and no location/autocomplete_city/be/..

So, i save my node with only country belgium, and when i edit again the form, autocompletoin works good with belgium cities and this address in firebug console :
location/autocomplete_city/be/..

Another issue :
I try after with france (no cities in database) and i don't know why but the autocompletion did on belgium cities (thought the address in firebug console was location/autocomplete_city/fr).
The bug didn't happen with US selected.

My english is worth, so i'm very sorry for that... and i'm not sure to be very clear so don't hesitate to ask me some precision

Cheers,

Tim

YesCT’s picture

@timos don't worry about your english. You did a good review.

Sounds like this needs a new reroll against the latest version of dev. It might be possible if someone tried to make the changes by hand. Also try a google search for:
drupal how to create patch

and ths needs a fix so it notices when someone changes the country.

Also i don't remember if this is in there or not but this would need a setting in the configuration to turn on and off auto complete and it would need to default to off, so it would not break anyone's existing site.

colan’s picture

I don't have a proper environment set up now to test this, and I never did. I just changed some code so that folks would start moving in a direction that uses zipcodes rather than doing it the old way. Sorry I can't help with testing right now.

The patch should work on its own, but, as mentioned above, will need to be rerolled.

khan2ims’s picture

Hi,

The auto complete is working on the forms now. Its great!

I am having a search form where I am exposing the city field. There it doesn't displays as auto complete field. What should I do to display this city field as auto complete on my search forms?

Thanks in advance.

juicytoo’s picture

Hi,

if this is working, can it be committed to a dev version.

There are so many patches available for location its hard to keep track of which ones apply.

In either case, for this to work, do we need to download the latest ver and then apply this patch?

Is this the general procedure for all patches?

Thanks.
Ed

YesCT’s picture

this cannot be committed until it has a config option (and the configuration setting defaults to the current behavior, which is not to use the autocomplete). that is why the status is "needs work".

Also, I'm not sure as mentioned in #41, if the autocomplete for search is a problem that needs to be fixed in this issue/patch, or if that is a separate issue. What do you all think?

Ed, yes, in general try to apply the patch to dev (actually... it is probably best to assume the patch works with whatever version is mentioned in the issue (see the issue information, near the beginning of the issue page) for the version. :)

If you are running any patches against location, please try to find an issue that addresses it (probably the issue you got the patch from) and make sure that issue is moving forward, getting reviewed if it needs reviewed. Or getting worked on if it needs work. The goal is to get it to apply against the most recent dev, and get it reviewed by 1 or 2 people so that it can be marked RTBC (reviewed and tested by the community).

http://drupal.org/patch/apply
http://drupal.org/patch/create
http://drupal.org/node/156119 (on issue statuses)
... I could not find a good overview of "how do I get a patch committed" ... try http://drupal.org/patch/submit

Also, a summary posted so the maintainer can quickly read a recent commend that summaries the original problem, the changes the patch makes functionality wise, the changes to the code in general and any effects it might have.

edjay’s picture

FileSize
5.49 KB

I have make a diff from the last 3.1
It's only my second patch so verify the file please.

YesCT’s picture

Status: Needs work » Needs review
vlooivlerke’s picture

Patch #44 Worked for me.

Latest stable gmap, drupal, location 3.1 with #44 patch worked out of the box for country South Africa.

To make the module use your country on activation, I first installed the zipcodes table, then replaced all US country calls 'us' with 'za'
There is about 3 of them in the location.module file.

Then activate the module as usual.

Here is a question.

The autocompleate shows the city name followed by a comma then its state/provance (Cape Town, WC)
Now if you fill in the province it outputs
(Cape Town, WC, WC) this does not look nice.

Thanks for the patch edjay

YesCT’s picture

Status: Needs review » Needs work

I think for this to be committed, it needs to have a setting in the UI, so people dont have to modify the code (to get it to work for non US countries) and also, the thing with the extra comma and province needs to be sorted out.

vlooivlerke’s picture

The extra comma, is a blessing!

I have been playing with the new input. If I enable geo-coding for South Africa (google) and only enable the Street and City fields in location, The full string sent to google contains

street, city, state/province

This is enough info for google to place the marker exact, so no need for the extra state/province field (that also auto-complete)

Makes sense, coz a town will only be in one state/province

If it could include the postal code too then a user can make sure, he gets to postal code level if he does not want to put his street address.

I think this is a valuable breakthrough. This enables you to only input 2 fields, where one auto-completes, so very simple to submit location.

P.S, I changed my State/Province short codes to the full names to guarantee google geo-coding to be exact. (simple find and replace function in Table)

zualas’s picture

Sorry but I'm not getting anything from the patch. I see the autocomplete widget, but it does not return anything. Here are the steps I've done

1) Applied the patch to v3.1
2) Loaded the US zipcodes into the database
3) Enabled the Location CCK widget with Country, Province and City fields

4) When I enter the country, the province suggestions are given, but the ones for the city aren't.

Am I missing something?

Thanks!

vlooivlerke’s picture

Try this.

Uninstall the location module, go to the zipcodes table to find it empty.
Then load us zipcodes.

Now enable module. Go to any content type and test auto-complete of city.

Make sure your patch is correct. I did mine by hand.

zualas’s picture

FileSize
32.14 KB

I tried to do as you said, but I'm getting this javascript error all the time. Tried both 3.1 and dev version, applied the patch manually.

Berliner-dupe’s picture

Hi,

the patch from #31 http://drupal.org/node/404830#comment-2912458 works fine for me - but - there is a little problem.

When i set the first letters from a city - then the autocomplete-field show me the City-Names AND behind the "State-Names"
Example: Berlin,BE

But - I dont need the State-Names - i need the country-Name.
Example: Berlin, DE or New York, US

I changed in Patch ....

SELECT DISTINCT CONCAT(city, ',', state) AS city FROM {zipcodes}
to
SELECT DISTINCT CONCAT(city, ',', country) AS city FROM {zipcodes}

but it have no effect. Cache is cleared.

Has anyone an idea?

Sorry for my bad english.

Thank you and Regards
Matthias

BenjaminG’s picture

Could this work for postcodes too?

I have a defined list of postcodes I want people to be able to select from when entering the location information. That defined list of postcodes is in the zipcode table. It would be really good if, when entering the postcode information, it selected the postcode from the zipcode table and autofilled the other information. That way I could use the location module for everything!

shopdogg’s picture

subscribing

SebastienT’s picture

Hi @Berliner,

I have the exact same problem...
Have you figured this out yet?

Regards

Berliner-dupe’s picture

@SebastienT

No - i dont found an answer for this problem.

I dont know how can i fix this.

bryancasler’s picture

subscribe

marcoBauli’s picture

humm.. autocomplete seems to work out of the box but on Location settings pages only (backend), not on node edit forms.

patch #31 didn't help..anyone knows how to make this work with latest version of Location? thx

ccheu’s picture

subscribe

petr.gorodechnyj’s picture

I used the patch #44: http://drupal.org/node/404830#comment-3180128.
Had a problem with some parts of location plugins (node_location and user_location). They seem not to be able to load all necessary entries from database if autocomplete path ends with country id. I used the "Array" instead and it solved the problem.

The fragment of location.module:

case 'city':
          drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
          $country = $a5['country'] ? $a5['country'] : variable_get('location_default_country', 'ru');
          return array(
            '#type'           => 'textfield',
            '#title'          => t('City'),
            //'#autocomplete_path' => 'location/autocomplete_city/'. $country,
            '#autocomplete_path' => 'location/autocomplete_city/Array',
            '#default_value'  => $obj,
            '#size'           => 64,
            '#maxlength'      => 255,
            '#description'    => NULL,
            '#attributes'     => NULL,
            '#required'       => ($a4 == 2),
          );

Oh, yeah, I replaced countries before from 'us' to 'ru', but this didn't change a thing.

P.S.> Well, the problem was somewhere else, probably, 'cause after I had 'white screen of death' on front page, I nearly reinstalled all the site. And after that I got 'location/autocomplete_city/Array' no working, so I rolled back to $country. But probably it will be useful for someone.

bryancasler’s picture

Issue tags: -location bdragon check

subscribe

prabhakarsun’s picture

Is this available for location CCK?

prabhakarsun’s picture

I wanted to have select box for states & autocomplete for cities. But #44 & #100 in http://drupal.org/node/364287 are not working together.

prabhakarsun’s picture

oops, it was my fault. Didn't clear cache.

vlooivlerke’s picture

@#52 To fix "City, STATE" dispay in autocomplete to "City" only

changed in Patch ....

SELECT DISTINCT CONCAT(city, ',', state) AS city FROM {zipcodes}
to
SELECT DISTINCT CONCAT(city) AS city FROM {zipcodes}

Uninstall location.module and reinstall to take effect or make this change before you install this module.
Some problems with the cache or something..

Anonymous’s picture

+1

chrislabeard’s picture

I've been trying to get this to work I patched it against 3.1, It tries to do something but it returns no results. I've imported all of the zipcodes.us into my db.

did I miss something or is it supposed to be with the dev version?

laraz’s picture

subscribe

leenwebb’s picture

Any progress on this? The patch in #44 applies just fine against 6x-3.1 (July 2010) but the auto-complete doesn't work; the field cycles and looks like it's searching but not finding any matches. I've cleared caches, reloaded the zip code table, un-and-re-installed module, etc. Has anyone been able to get this to work with US cities/states?

vlooivlerke’s picture

FileSize
350.99 KB

Here is my version, also has some auto complete fixes for state/province

From my production site.
Install location, then fill empty zip codes table, then only install location node module.
enjoy.

lyleadmin’s picture

Category: feature » support

subscribe

ankur’s picture

Status: Needs work » Closed (won't fix)

Autocompleting for cities is the kind of bloat I'd like to keep out of this already gargantuan, monolithic module. I'd encourage anyone that is seeking this functionality to implement it as a plugin or as a custom one-off in your project.

Summit’s picture

Hi,
I understand what you are saying, but it would be great if people still post there plugin, custom one-off so other can benefit from it.
Would love a google maps sort of integration of countries, cities etc..
Thanks still for this great module!
Greetings, Martijn

pragna’s picture

#44 patch is working for me, but it is not finding any city for any province of any country.
Please help me how to add all cities of all country.

pragna’s picture

Version: 6.x-3.x-dev » 6.x-3.1
Priority: Normal » Critical
Status: Closed (won't fix) » Active
Alan D.’s picture

Priority: Critical » Normal
Status: Active » Closed (won't fix)

@pragna Ankur is a maintainer of the module, so has the right to close a feature request. Also no feature request should ever be considered critical!

jim005’s picture

subscribe

colan’s picture

@websenso_com: There is no need for subscribe comments any more. Simply click on the "Follow" button at the top of the issue.

drupalina’s picture

Version: 6.x-3.1 » 7.x-3.0-rc5
Status: Closed (won't fix) » Active

I'm reopening this issue to see if anyone has come up with a plugin for 7x.
I have manually implemented the patch in #44 (in 7x the names of those functions are all the same, so it was easy to find) and changed default country from 'us' to 'au' (which is among the databases). The autocomplete toggle gets activated, but then the browser spits out an AJAX error, so basically it doesn't work.
Has anyone found a solution for 7x version of Location?
I'm also looking for a similar autocomplete functionality for the Location field in exposed proximity search.

PS: I understand that autocomple for Cities and exposed filters is a BIG task, but here is a question: how often do you go to a decent website and not see the location field be autocompleted? Never! In this day and age the end-users expect it to work.

nstahl’s picture

subscribe

podarok’s picture

Version: 7.x-3.0-rc5 » 7.x-3.x-dev
Category: Support request » Task
Issue summary: View changes
Status: Active » Needs review

The last submitted patch, 31: city-autocomplete.patch, failed testing.

The last submitted patch, 44: location_autocomplete.patch, failed testing.

The last submitted patch, 2: location_autocomplete_cities.patch, failed testing.

podarok’s picture

Status: Needs review » Needs work
Issue tags: -location auto-complete

nothing to review yet

dancor’s picture

any news?

Agiss’s picture

Hi guys,

We have started working on a patch for Cities autocomplete and Postal Code autocomplete for Location version 7.x-3.7.

Please have a look at https://www.drupal.org/node/2712081#comment-11129657

Hope this helps

Cheers
Agis