create some nodes with multiple addresses. store them in geofield.

create new view

add both, address field and geofield

set both to Display all values in the same row = no

preview

the lat/lon info is different but the addres info is the same for all the fields

i'm not sure if this is an issue for geofield or for addressfield.

can somebody confirm it?

thank u

Comments

nod_’s picture

can you provide an export of your view and content type please ?

dgastudio’s picture

views

$view = new view;
$view->name = 'travel_route';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Travel route';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Travel route';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Geofield */
$handler->display->display_options['fields']['field_geo']['id'] = 'field_geo';
$handler->display->display_options['fields']['field_geo']['table'] = 'field_data_field_geo';
$handler->display->display_options['fields']['field_geo']['field'] = 'field_geo';
$handler->display->display_options['fields']['field_geo']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_geo']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_geo']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_geo']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_geo']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_geo']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_geo']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_geo']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_geo']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_geo']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_geo']['click_sort_column'] = 'wkt';
$handler->display->display_options['fields']['field_geo']['type'] = 'geofield_latlon';
$handler->display->display_options['fields']['field_geo']['settings'] = array(
  'data' => 'full',
  'format' => 'decimal_degrees',
);
$handler->display->display_options['fields']['field_geo']['group_rows'] = 0;
$handler->display->display_options['fields']['field_geo']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_geo']['delta_reversed'] = 0;
$handler->display->display_options['fields']['field_geo']['delta_first_last'] = 0;
$handler->display->display_options['fields']['field_geo']['field_api_classes'] = 0;
/* Field: Content: Postal */
$handler->display->display_options['fields']['field_postal']['id'] = 'field_postal';
$handler->display->display_options['fields']['field_postal']['table'] = 'field_data_field_postal';
$handler->display->display_options['fields']['field_postal']['field'] = 'field_postal';
$handler->display->display_options['fields']['field_postal']['label'] = '';
$handler->display->display_options['fields']['field_postal']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_postal']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_postal']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_postal']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_postal']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_postal']['element_default_classes'] = 0;
$handler->display->display_options['fields']['field_postal']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_postal']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_postal']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_postal']['click_sort_column'] = 'country';
$handler->display->display_options['fields']['field_postal']['settings'] = array(
  'use_widget_handlers' => 1,
  'format_handlers' => array(
    'address' => 'address',
  ),
);
$handler->display->display_options['fields']['field_postal']['group_rows'] = 0;
$handler->display->display_options['fields']['field_postal']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_postal']['delta_reversed'] = 0;
$handler->display->display_options['fields']['field_postal']['delta_first_last'] = 0;
$handler->display->display_options['fields']['field_postal']['field_api_classes'] = 0;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['nid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['nid']['not'] = 0;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: travel route */
$handler = $view->new_display('block', 'travel route', 'block');
$translatables['travel_route'] = array(
  t('Master'),
  t('Travel route'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Geofield'),
  t('All'),
  t('travel route'),
);

how to export content type in d7?

nod_’s picture

It's simple enough, don't worry about the content type i'll test that when I get home.

dgastudio’s picture

any update on this?

Brandonian’s picture

Status: Active » Closed (cannot reproduce)

Everything seems to be working as expected. There's an odd display issue with the geocoder widget (which has been noticed at #1345054: Geocode field sin't hidden when set to multiple values), but otherwise, the output from views spits out what one would expect.

In my demo, I had a single node with one addressfield and one geofield, each allowing multiple values. I created a single node with 2 geocoded addresses. When I rendered the view as described above, the view displayed 4 rows...

- Address 1, Geofield 1
- Address 1, Geofield 2
- Address 2, Geofield 1
- Address 2, Geofield 2

While this obviously isn't the display that you'd want if you're trying to display unique addresses, this is the same display that you would get if you tried to write a single SQL query in the same manner as Views. In order to remove the incorrect addresses, you would probably want to skip one of the fields in the view and do some sort of rendering tweaks in the theme layer.

Manuel Garcia’s picture

Status: Closed (cannot reproduce) » Active

Using the latest stable version as of today from both modules, geofield 7.x-1.1 and addressfield 7.x-1.0-beta3

Both fields set to infinite values on the content type, entered 2 values for the address field while creating the node.

Ive setup a view using the Geofield Map style plugin, added both the address field and geo field as described above (display each value in a new row), and although the points are placed correctly on the map, the info bubbles show the same address, instead of each one its own address..

I'm going nuts here trying different configurations on the view, but none seem to work properly. I'm using EVA field as the way to get the view inside the node.

I have also tested creating a standalone page display, but the problem still persists, if a node has several address field values, the points are setup properly, but the bubble show the same address data (I believe only the last value in the field).

ceepeebee’s picture

Geofield 7.x-2.1 & Address Field 7.x-1.0-beta4

The problem is using the method described above (addressfield with multiple entries, geofield with multiple entries, in views: Multiple Field Settings: Display all values in the same row switched off), you get with an unformatted list format:

#1: Address 1, Geodata 1
#2: Address 1, Geodata 2
#3: Address 2, Geodata 1
#4: Address 2, Geodata 2

With geofield map format enabled, these results are still rendered in the same order.
The first two markers will get covered by markers #3 and #4. That's why they are at the right locations but both locations showing address 2 in the popup.

What you want is 'Geofield Map' rendering only the results of #1 an #4. Then you get marker 1 at position 1 with address 1 and marker 2 at position 2 with address 2.

There is an easy (not perfect) way and the option to use hook_pre_render() in a custom module to modify the results shown above before they are used for rendering. (of course, there are some more options, like altering the mysql query constructed by views using Views Raw SQL and the like. But I think two choices are quite enough)

Views 7.x-3.7+12-dev! Read the comment right at the bottom! Maybe you can now have a perfect way 1... I didn't test it yet.

Way 1: easy but not perfect (yet)
a) use the settings as described above
b) for the addressfield(!) turn on the option to display all values in the same row, you'll get:
[the brackets indicate that it is one rendered field (in listview)]

#1: (Address 1, Address 2), Geodata 1
#2: (Address 1, Address 2), Geodata 2

That's still not, what you want, but you have only 2 markers left. So there are no markers secretly overlapping. Now you'll get both addresses shown at both locations. For some use cases this could suffice. For others not. (It could get confusing if you had, let's say, 10 addresses to show, or so.)

c) You could add another column " Global: View result counter", the result would be:

#1: 1, (Address 1, Address2), Geodata 1
#2: 2, (Address 1, Address2), Geodata 2

To get the same result with a geofield map format you have to do the following:
click format settings next to 'geofield map'; choose your address-field as popup-text source;
rearrange your fields to get the counter field in front of your address field; configure the address-field to rewrite results: enable "rewrite the output of this field" and use for example
<span>[counter]</span> [geofield]
[you could also wrap the address-field with custom html and set a class also using the [counter]-token, but this didn't work right now]

At this point you would have to switch to javascript for example, because views ui doesn't give you any chance to access the different parts of the rendered addressfield. I'm not quite sure if the html and class structure you can build enables you to select the rows you want to show via css. Maybe there is a way, but you shouldn't actually use css for logical operations...

With Javascript you could easily read the value of the counter and display only the correct address. You could even hint for the other related addresses via pop-up and so on.

Way 2: just a little bit of coding required
The cleaner approach is via manipulating the returned data before it is (fully) rendered and put into display. For this solution you need to write your own module. Use the Features module if you are lazy ;)
a) prepare your module's basics
b) prepare the view as described at the beginning of this post (not way one); the data will be easier to process.
c) go to my_geomap.info and include files[] = my_geomap.views.inc
d) create my_geomap.views.inc

be aware: due to binary storage of some geo data you can't use dpm($view) et al to get help on variable names and values within the hook_views_pre_render() et al;

/**
 * Implements hook_views_pre_render()
 */

function my_geomap_views_pre_render(&$view) {
  // for performance reasons only do the stuff below, if we are viewing the geomap view
  if ($view->name=='my_geomap') {        // use the machine_name of your view's display
    
    // loop through the results which we got back from the database
    foreach ($view->result as $i => $row) {  
      // as we learned right at the beginning of this post, we only want to select #1 and #4
      // in general:
      // these are the result sets (rows) where the address-delta equals the geodata-delta
      // !!!you have to use the proper field names (better: table names)!!!
      // use the table name you can find in your database (without the suffix)
      // and append "_delta"
      if ($row->field_data_field_user_address_delta != $row->field_data_field_user_geodata_delta) {
        unset($view->result[$i]); // delete all the result sets we don't want
      }
    }
  }
}

e) save and enjoy.

If you wanted to, you could pimp the returned results even more. There are (almost) no limits.

There is a new version of views: 7.x-3.7+12-dev ! I didn't try it yet, but I heard, it allows you to set a filter via ui like: compare field1 with field2
If this is truely possible, you could easily set a filter, which does the same comparison as we did in the hook_views_pre_render()...

ceepeebee’s picture

Title: address field and geofield in views: Display all values in the same row = false: returns wrong result » Addressfield & geofield in views: How-To display multiple addresses stored in the same (multi-dimensional) field
Version: 7.x-1.x-dev » 7.x-2.1
Component: Code » Documentation
Category: Bug report » Support request
Issue summary: View changes
Status: Active » Needs review

just posted a how-to with different approaches to solve this 'mystery'.
The original issue was no bug, but a support request -> updated category
The issue is still current --> updated version
The thread targets on documentation, I guess -> updated component
Someone should probably confirm the how-to -> updated status
Tried to find a more suitable title -> updated title

ergophobe’s picture

Method 2 in #7 works perfectly.

Thanks!

foonambolo’s picture

Hello,
I had exactly the same problem (i still have it) I followed the instructions in comment #7.
When i print the results of my view as simple text i get my nodes with their two rows with two adresses and their coordinates, as I expected, fine.
If i disable my hook_views_pre_render module i get again 4 rows each node, so I think it's working.
The problem is that if I switch my view display as leaflet map I get again 4 markers each node, two per address.
I don't know what I can do now.
I installed even marker cluster so now I can see exactly two markers each address, if i click they explode and I can see both addresses on each marker.
I hope I've explained well enough my situation.
Thanks a lot, any help is appreciated

Marco

P.S. i used method 2 in drupal 8