Some sort of reusage of already used locations has been addressed earlier. First step would be to make the user interface better, using autocomplete to fill in certain fields. Duplicate, or more usage of one particular coordinate should be avoided, but having autocomplete on cities, countries would certainly improve the interface as users assign multiple locations to one city, country.

Here is a patch to Drupal 5 that implements basic autocomplete function for the "city" textfield. Further option to extend it to other fields via the $ltype variable in the function.

Further plans: apply this to country selection, I will open a new issue on that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

marked #139761: Prepopulate Cities? as a duplicate of this request.

YesCT’s picture

Issue tags: +location auto-complete

tagging

juicytoo’s picture

I would like to contribute $20 towards this feature.

Is there a donate button anyway on the project page?

ankur’s picture

Version: 5.x-1.x-dev » 7.x-4.x-dev
Status: Needs review » Postponed

Sounds like a nice feature, but something very specific. There're also a lot of open details, such as how do you compose a list of auto-complete cities for different locales? For some countries, this could be through the use of country/province values already entered while for others just country. This probably needs to be thought out and then evaluated for whether we have the resources make this happen.

ellocin’s picture

Title: Location autocomplete implementation for cities » Location autocomplete implementation for cities
Version: 7.x-4.x-dev » 7.x-3.x-dev
Issue tags: +7.x-3.x-dev
FileSize
4.59 KB

Hello,

Here is a patch for autocomplete city in Location 7.x-3.x-dev. I don't know if someone would be interested by this patch....

I came to drupal/php few month ago so please let me know if this patch (my first !) needs to be improved.

best regards,

kaizerking’s picture

#5 This patch cannot be applied
The patch cannot be applied in current context
Is any one having a solution for this?

jordiserra’s picture

Any news on this subject? I am very interested in autocomplete for cities. If I can help in some way, module admin please tell me!

kaizerking’s picture

#5 ellocin can you please re-do this patch, there is lot of difference in current version hence. even to apply manually I can't find the code where to put to put this.

jordiserra’s picture

I applied the #5 patch manually and it works for my project. I think the dropdown can be easily included also.

I can't verify it always works, but at least it does with user locations. It should be included in the module, because if you want to classify content by city, you can't do it if the user enters the city name, there always will be mistakes and inconsistences.

I don't know if it is very difficult, but with no doubt it would be very useful.

YesCT’s picture

@jordiserra if you applied the code manually, can you do a diff, and post that so it can be used as a newer patch?

osysltd’s picture

Subscribing. Please post a patch to stable version.

laraz’s picture

I need this patch to the verisio 7.x-3.0-alpha6.

thanks.

podarok’s picture

Status: Postponed » Needs review
Issue tags: -location auto-complete, -7.x-3.x-dev

bot?

podarok’s picture

#5: location_city_autocomplete.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, location_city_autocomplete.patch, failed testing.

podarok’s picture

#5 needs reroll against latest 3.x dev

kaizerking’s picture

Here is the patch that applies to 7.x-3.x-dev

podarok’s picture

Status: Needs work » Needs review

bot

podarok’s picture

+++ b/location.moduleundefined
@@ -769,9 +773,21 @@
+          }
+        	return array(
+++ b/location.moduleundefined
@@ -972,7 +988,58 @@
+    // Multiple countries specified.
+    ¶
+    $country = explode(',', $country);
+++ b/location.moduleundefined
@@ -972,7 +988,58 @@
+  else {
+    ¶
+	  ¶
+		$matches=location_get_cities($country,$string);
+   ¶
+  }
+ ¶
+  drupal_json_output($matches);
+++ b/location.moduleundefined
@@ -972,7 +988,58 @@
+function location_get_cities($country,$string){
+	$matches=array();
+	$query=db_select('zipcodes','z');
+		
+	$result=$query->fields('z',array('city'))
+		      ->condition(db_and()->condition('z.city',"%$string%",'LIKE')->condition('country',$country,'='))
+					->range(0,20)
+					->execute();
+
+  foreach ($result as $obj) {
+			 $matches[$obj->city]=check_plain($obj->city);
+	}
+
+	return $matches;				¶
+}
+
+++ b/location_autocomplete.jsundefined
@@ -28,10 +28,41 @@
+   }).addClass('location-processed');
+  ¶
+  ¶
+    $('select.location_auto_country:not(.location-processed)', context).change(function(e) {
+++ b/location_autocomplete.jsundefined
@@ -28,10 +28,41 @@
+      }).addClass('location-processed');
+  ¶
+  } // attach

lot of whitespace and indentation error
http://drupal.org/coding-standards#indenting

+++ b/location_autocomplete.jsundefined
@@ -28,10 +28,41 @@
 })(jQuery);

\ No newline at end of file
http://drupal.org/coding-standards#comment-5262644

Should be fixed before RTBC

podarok’s picture

Status: Needs review » Needs work

due to #19

dancor’s picture

bump

is the autocomplete working? I see there a location_autocomplete.js file, can I use this and how can I use this?

lchang’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
4.62 KB

Fixed whitespace and indentation error in kaizerking's patch.

Status: Needs review » Needs work

The last submitted patch, 22: location_city_autocomplete-137405-22.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: location_city_autocomplete-137405-22.patch, failed testing.

lchang’s picture

"Location Google Geocoder tests(broken!!!)" can be passed after applied the patch in issue 2406483.

kaizerking’s picture

removed the coding standard issues

kaizerking’s picture

Status: Needs work » Needs review
podarok’s picture

Status: Needs review » Needs work
+++ b/location.module
@@ -972,7 +988,58 @@
+	$matches=array();
+	$query=db_select('zipcodes','z');
+		
+	$result=$query->fields('z',array('city'))
+		      ->condition(db_and()->condition('z.city',"%$string%",'LIKE')->condition('country',$country,'='))
+					->range(0,20)
+					->execute();
...
+			 $matches[$obj->city]=check_plain($obj->city);
+	    }

Please, follow drupal coding standards. https://www.drupal.org/coding-standards#indenting
We should use white spaces instead of tabs.

+++ b/location.module
@@ -972,7 +988,58 @@
+  //$string   = '/^' . preg_quote($string) . '/';

we should avoid of using commented code

kaizerking’s picture

Ok done

kaizerking’s picture

Status: Needs work » Needs review
podarok’s picture

Status: Needs review » Needs work
  1. +++ b/location.module
    @@ -972,7 +988,58 @@
    ++ *   String (optional). The city name typed by user
    ++ * @return
    

    @return shoud have empty line before

  2. +++ b/location.module
    @@ -972,7 +988,58 @@
    +function location_get_cities($country,$string){
    

    function should have docblock

  3. +++ b/location.module
    @@ -972,7 +988,58 @@
    +		
    

    remove whitespaces, according to Drupal coding standards

  4. +++ b/location.module
    @@ -972,7 +988,58 @@
    +    $result=$query->fields('z',array('city'))
    

    '=' should have spaces around it

  5. +++ b/location.module
    @@ -972,7 +988,58 @@
    +	    }
    

    remove whitespaces, please

There are a lot of issues with code style. Need fix.

max-kuzomko’s picture

Assigned: Unassigned » max-kuzomko
max-kuzomko’s picture

Issue tags: +dcuacs2015
max-kuzomko’s picture

Fix #32

max-kuzomko’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: location-137405-10052530.patch, failed testing.

max-kuzomko’s picture

Fix #35

max-kuzomko’s picture

Status: Needs work » Needs review
Valentine94’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, let's RTBC

  • podarok committed d86895a on 7.x-3.x authored by max-kuzomko
    Issue #137405 by kaizerking, max-kuzomko, lchang, ellocin, snufkin,...
podarok’s picture

Status: Reviewed & tested by the community » Fixed

thanks, merged

Status: Fixed » Closed (fixed)

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

Kristina Katalinic’s picture

Hello,
can anyone please explain how I use this feature? Because, when I type in first couple of letters of any Australian city nothing is being autocompleted and I can't find a settings form where I can add a list of cities that should be available on autocomplete form.
Thanks in advance

Kristina Katalinic’s picture

Status: Closed (fixed) » Needs work

Ok, I figured it out, zipcodes need to be imported into the database and then it works ok.
However, using autocomplete user is able to input a "fictional" location that does not actually exist and is basically identical problem as originally described when issue was first created as we can end up with Locations that don't actually exist. Based on my experiences with building directory type websites there is also a slight "issues" with any of the cities from database showing up regardless of the state/province that was previously selected so we can end up with a city of Sydney in state of Queensland even though it only exists in the state of New South Wales...

Perhaps put a permission on the field so user can only pick cities already in database and cannot add a new city or, provide a select option instead of autocomplete? Either way would prevent the user from entering a location that is not already recorded in the database so perhaps adding a "select" option would be more practical as it would add on to the feature.

Agiss’s picture

Hi guys,

We have started working on a patch for cities 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

ydahi’s picture

I came here searching for an autocomplete solution for Location field exposed filters for views (in my case the field I wanted this functionality was: city). Went searching and found a fully functionally solution here:

https://www.drupal.org/project/views_autocomplete_filters