I have a seemingly simple problem, but I've been stuck with it for some time now.

I have a big database of nodes of one content type. There are addresses there made of text fields: one field for street, one for city etc. Province is a predefined taxonomy. I'd like to use 4 of these fields, including province, to get a string that can be geocoded as lat/lon for a map.

I also need these fields to be useable in Views (e.g. as filters like a province filter, as tokens etc.). It is doable in GMaps + Location (Views module recoginzes each locative entry as a separate field), but GMaps is seemingly an obsolete module, and it forces me to use predefined provinces which is not cool.

Also, I need to display a small map when a user displays one of the nodes, and the other for the home page with all the locations marked and ready to get filtered out by exposed filters.

I thought maybe geocoded Field Collection is an option for me, but the separate elements of such a field are strangely not visible in Views module as filtering/sorting criteria. I also tried the Computed Field, but there is a bug which prevents its text output from being geocoded. ( http://drupal.org/node/1679926 -- bug desc.)

Am I missing something? Are there any other simple ways to get a map made of custom fields as address elements?



You can use the Geocoder module. It will geocode pretty much anything you through at it. Even your already set text fields. In the fields settings you can use a multi-selct to select which field you would like to geocode from. Allowing you to specify all of your text fields and taxonomy field. Then you can just use the OpenLayers module to display your locations on a map (single and combined).

Edit: Attached screenshot of Multiselect

enter image description here

  • That's true except that the "Geocode from field" option allows for only one selection. (Unless I am doing some super-stupid mistake and do not see some obvious setting, but I re-checked it for a gazillionth time now.) Still, that would be fine if there was any method to combine all the necessary address fields on-the-go into one text string for Geocoder. One such method might be Computed Field module which does not work due to a bug (as mentioned above)... – Zen Sep 20 '12 at 17:10
  • I have edited my answer to add a screenshot of my Geofield settings which allow me to select multiple fields while holding down CMD (MAC) or CTRL (PC) and clicking the fields I need. I am not sure why you cannot select multiple fields. – user842 Sep 20 '12 at 18:53
  • Would you please tell me, which version of Geocode module you are using? In my case it's 7.x-1.2. Because multiple selection was reported as bug and "fixed": drupal.org/node/1339904 – Zen Sep 20 '12 at 19:55
  • I have it working in both 1.1 and 1.2 – user842 Sep 20 '12 at 20:36
  • Also make sure you are using the combo of Geofield and Geocoder. – user842 Sep 20 '12 at 20:39

Based on the issue you mentioned I assume it is Drupal 7. So the first thing I would do is move the address from each elements to Address field. Address is fully compatible with tokens as well as views and will give you support for all the countries and states and you do not have to work it on your own using taxonomies.

To do this you can have a look at Migrate and Migrate Extras.

Once you are done with this you can have a look at you can use the geocoder, geofield and openlayers to get the desired output.

But it is definitely some work.

  • Thank you! The trick is that I need and prefere to use custom taxonomy, as: 1) the Addess Field module does not even provide province field for my country (Poland), though my regional settings are set ok, 2) I want to make an exposed filter basing on province and use Better Exposed Filters mod which works only with dropdowns, 3) hard coded set of Polish provinces (at least the one provided by Google locative option) lacks diacritics which is unacceptable on production site, 4) it's better for a user to just click a radio button next to one of only 16 provinces than manualy enter its name. – Zen Sep 20 '12 at 16:14
  • Just have a look at this file addresfield/format/plugins/address.inc and you can easily add Poland province and once you have tested it you can give it as a patch as well for the address field module.This is justa suggestion. – junedkazi Sep 20 '12 at 16:30
  • I'd love to if I only new how. I am next to a newbie in Drupal and I'd rather not mess with code (for now). – Zen Sep 20 '12 at 17:12
  • OK, now I see it's quite easy, so I guess I will write a patch. Thanks for the suggestion. Still, my problem persists. – Zen Sep 20 '12 at 18:25
  • which part is pending ? – junedkazi Sep 20 '12 at 18:33

This may not answer your entire question, but may help you get to the answer. Here's how I added simple maps based on the address in a node:

  1. Used the Address Field module, which has a very clunky interface but supports international addresses. (Fields change dynamically based on which country the user selects.)
  2. Used Views to display my nodes, but you could also use custom fields via Display Suite or other solutions.
  3. Used the following code (as a rewritten field in Views) to create and embed a map of the address on each node. (I converted all > and <'s to curly brackets so it would display, see unmodified code at http://pastebin.com/gR9Hxn9a. The square brackets are referring to other fields in Views.)

{a href="http://maps.google.com/?q=[field_location_address-premise]+[field_location_address-sub_premise]+[field_location_address-thoroughfare]+[field_location_address-locality]+[field_location_address-dependent_locality]+[field_location_address-postal_code]+[field_location_address-administrative_area]+[field_location_address-sub_administrative_area]+[field_location_address-country]" target="_blank"} {img src="http://maps.googleapis.com/maps/api/staticmap?markers=[field_location_address-premise]+[field_location_address-sub_premise]+[field_location_address-thoroughfare]+[field_location_address-locality]+[field_location_address-dependent_locality]+[field_location_address-postal_code]+[field_location_address-administrative_area]+[field_location_address-sub_administrative_area]+[field_location_address-country]&zoom=7&size=200x150" class="locationmap" /} {br /} [field_location_address_1]{/a}


You could DSM out the fields in the template (node or view) and use the field values, and build up a map using just an embed code with your address, and manually attach those values into an iframe embed inside your template file. Just an idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.