0

This question already has an answer here:

In Drupal 7,

I am using the postal address field to input my address, and then i used the geofield to geocode my location from the address field. Here, the geofield will converte my address into coordinates, i will use those coordinates to show my address on a map (ex. Leaflet map)

However, the problem is that the City field in the postal address is showing for users as a text box and so there is a big chance for any user to wrongly write his city name inside this text box and so his address it will not shown on the map.

See the attached image

Address field displaying the city as a text box

To prevent such problem, i would like to replace the city textbox by a taxonomy reference where all the city in my country exist as terms and so the user will just pick up his city.

Any suggestion on how to accomplish the above ?!

marked as duplicate by mpdonadio Apr 15 '17 at 16:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Wouldn't that be thousands and thousands of terms? – Kevin Apr 13 '17 at 23:35
  • Actually it will be around 8 terms for the governorate vocabulary and not more than 1200 terms for the cityvocabulary. Since i have all of them already inside taxonomy so it will be better to display them to the end user using a taxonomy reference field or similar approach – user74624 Apr 14 '17 at 3:59
0

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

I found this module which is exactly what i really want to do! Without mentioning that it is not stable and it seems to be for estonian nationlaities only

0

I hope this answer will help

1) I created one vocabulary taxonomy: Custom Address

2) The terms inside the custom address vacabulary should be in the following format: [Country], [Region], [City] So as per my case i used: Lebanon, Mount Lebanon, Tabarja

3) Do the same for every city you want to include in your website.

4) In your content type, create one field of term reference the custom address vocabulary.

5) then i created a field with type: geofield and in the field settings i selected to geocode from the custom address taxonomy reference field.

6) Voila! When you create a new content and you select the a city from the custom address taxonomy field, your address will be shown on the map.

I know there is too much work to do especially if you have plenty of cities but at least this answer is better than nothing.