i saw the discussion about gmap having problems showing the node's location, when using CCK. but i don't even get the field itself to display it's content

when i build a view with fields and insert a CCK location field, it's empty, though i know i did put an address in the field.

is this a bug or am I (doing something) wrong?

#18 location_cck.field_format.patch954 bytesnickl
Members fund testing for the Drupal project. Drupal Association Learn more


YesCT’s picture


YesCT’s picture

are you getting the nodes listed in the view ok (via filter), but just not being able to add the data for display (fields)?

JIspahany’s picture

I think I am getting the same problem. Where I create a view and try and filter the contents of the Location field (Location:City for example). It is able to find the field but the contents of the field (Location:City) shows as empty.

YesCT’s picture

There is a patch to add a relation, ...
this one seems to be the way things are heading:
#347030: location_cck needs a views relation

drupaloo’s picture

I am also having the same problem:

- I have a number of CCK location fields
- I have created a view that contains those fields
- The view shows CCK location field headings but NOT their contents - Eg: The View displays a Country field label but the actual contents of each record, eg. Canada, Netherlands, etc. is not displayed.
- I have triple checked that the Location country field does contain data eg. Canada, Netherlands, etc.

From reading various posts I am not sure if there is a final patch or if a relationship needs to be added to the view.

Could you please let me know how things stand?


YesCT’s picture

there is a patch (to implement the relationship) and then you have to add the relationship.

drupaloo’s picture


Thanks for getting back to me.

To be honest, I looked at applying a patch in a Windows environment, and it looked pretty complicated, and so I would rather wait till the module is revised.

alvinet’s picture

Any news or new feature for this module to implement this function?
I have the same problem. Adding Location field to a view doesn't return any value.

fred0’s picture

I am also seeing this. I tried to describe it in another issue (http://drupal.org/node/383244#comment-2059868) but I think I did a poor job.
Now that I've done some more research, I can elaborate more clearly.

First, to respond to YesCT in #6: True, you can use the patch from http://drupal.org/node/383244#comment-1877654 and it adds the proper relationship functions but it 's more of a workaround to a bug in Location CCK.

I'll explain, but let me first describe the data storage for those unfamiliar. When you save a node with Location CCK data, it saves the location data in the tables created by the Location module. CCK modules usually rely on CCK to create and manage the required tables and then store the data in those tables. Location CCK instead stores the lid in the CCK table as a reference to the record it saved to the location table. When you view Location CCK data in a node that it has been added to, the module uses that reference to find the location in the other table and display the data.

Views then shows several fields as being available. Because the Location module is enabled, one sees a group of fields under the title Location such as Location:City. These are the individual parts of a location as provided via the Location module. One also finds a field under Content that is named for any Location CCK field you created.

Views should display the CCK field type, but adding it to a view returns empty data. It does not matter what widget format one chooses for the field (Address, Address with map, Map, Map with multiple locations), it always displays empty data. That's the bug I have been trying to figure out today without any luck (so far).

Adding any of the individual Location fields also shows empty. This is because the location data was not created by Node Locations and is not related to the node in a way that Location knows about. It's related only via the lid in the CCK record. To get around that, the patch adds the ability to create a views relationship to the CCK reference that those fields can then use. With the relationship in place, one can now use the individual Location fields and display the address or its individual components.

For myself, I want to use the latter method of using the CCK field because of its ability to display the address with a map but, as I said, that's not working.

hellomobe’s picture

fred0 - did you just update the patch for the 7.31.09 version of location_cck.module, or did you update the entire Location package from March 2009 to the July development package?

Please explain how to set up the location relationship in views. I don't see location as an option.

fred0’s picture

I believe I patched the 7-31-09 dev version.

hellomobe’s picture

I'm still not seeing where I can select Relationship => Location. I have applied the patch and no luck. Please walk me through the process when you have a moment. Very grateful!

TKS’s picture


cdale’s picture

You can fix this issue by adding the following code into a module or theme, and naming accordingly.

 * Preprocess hook for location().
function MODULE/THEMENAME_preprocess_location(&$variables) {
  if (!isset($variables['location']['name']) && isset($variables['location']['lid'])) {
    $variables['location'] = array_merge($variables['location'], location_load_location($variables['location']['lid']));

The problem simply appears to be that the location is not loaded up correctly when it comes time to theme it. This will not fix the bug, but it will suppress the issue until someone has time to figure out what is really going on.

EDIT: Don't forget to flush the theme caches after adding this function. You can do this by visiting admin/build/theme, or using cache clearing functions provided by admin_menu, devel, and some themes.

TKS’s picture

Thanks cdale -- this works like a charm!

nickl’s picture

Status: Active » Closed (duplicate)

Duplicate issue:
Moved to CCK/Views: location_instance fix with a patch for a permanent solution ready to be reviewed.

nickl’s picture

Title: how to: display the location from a CCK field (the address, not a map or anything) in views » Content: Location views field always blank
Category: support » bug
Status: Closed (duplicate) » Active

My bad! fred0 explains the bug well in #9 if I read it properly the first time round. Changed to bug report and made active again.

This does not relate to the individual location fields (city, country, street, etc) but to the cck exposed field which carries the lid (location id). The query works and returns the lid but the location information is not retrieved hence the theme_preprocess quick fix suggested by cdale in #14.

nickl’s picture

Status: Active » Needs review
954 bytes

I believe this bug came to be after optimizing the hook_field load so that cck can cache the location data, which allowed us to remove the location loading from the theme functions. http://drupal.org/node/383244#comment-1291018

This is all true for node fields but when views displays the field drupal_render is bypassed and views content handlers are used to render the fields and the locations are never cached for the themes.

This patch is another approach at solving the problem via hook_field sanitize, identifiable through a pseudo-node generated by the content handlers.

All but one of the formats are working; 'Multiple field values on a single map'. Any suggestions?

thill_’s picture


light9’s picture

Thank you cdale! your solution works for me!

l-r’s picture

Category: bug » support

I don't know if my problem falls under this category...

I'm trying to set a relationship - "Content (Location)" to use with GMAP + cck + views, but I simply can't see the "Content" option. There's a few other things I can select (comment, node revision, taxonomy...) but not matter I do, they never change.


Anonymous’s picture

Don't know if this is what you're after but this helped me set up a gmap + cck + views page:

- install latest dev versions of gmap and location modules
- install patch at comment #59 here http://drupal.org/node/391160
- create view using method at comment #4 http://drupal.org/node/386848

l-r’s picture

Thanks totsubo,
seems like the patch #59 (second link) did it!

Marko B’s picture

#22 works only for block display of CCK field. If i wanted to use block, probably i wouldnt use cck fields at all. This Location CCK patches stuff is complet mess :-(

emilyf’s picture

thanks cdale; #14 works great.

choofins’s picture

cdale nailed it with #14. Make sure to flush your cache by visiting your themes page.

frob’s picture

#14 worked for me.

Nothing was loading from the location except the lid. This is still a workaround though. I have not tried the patch or the dev branch mentioned in #16

Jackinloadup’s picture

#14 worked for me.

seanr’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #18 solved this problem for me. Appears to work well.

hm2k’s picture

Got a similar problem using Location 6.x-3.x-dev.

You can fill out the location details, hit preview and that will display as expected.

When you hit save, the location field is left blank.

Upon editing the node again, the location details have disappeared.

It was previously working on other nodes, but editing/saving recent nodes makes the location details disappear.

Will be disabled until a fix is proposed.

Any updates or advice?


marcxy’s picture


eiland’s picture

Patch #18 doesnt work for 3.x-dev. Neither does 14.

HongPong’s picture

Subscribing -- pretty serious

cha0s’s picture

Yup... still happening.

Patch from #18 applies with fuzz on 6.x-3.1; works.

JayKayAu’s picture

Category: support » bug

+1 Same situation, patch from #18 works on 6.x-3.1

glennpratt’s picture

Same issue, #18 appears to work here as well.

nickl’s picture

Title: Content: Location views field always blank » RTBC Content: Location views field always blank

Also been RTBC for two months already, please commit!

planctus’s picture

At last...i found this.
Cck location is now working using the patch at #18
Is there any reason why this hasn't been committed in a release here, yet?
Anyway, thanks,

rooby’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch.
I have committed a modified version of the patch in #18 to 6.x-3.x and HEAD.

Note though that this code isn't valid for drupal 7 but I committed it to keep the versions in line until the D7 version is properly ported. That way no functionality will be lost.

I changed it so it checks that the location has not been previously loaded, instead of checking for a pseudo-node from views content_handler_field because that way we cover other times when the hook_field load $op is not called, for example any modules or themes that use content_format() to output a field might not use the same sort of pseudo node.
I also made the comment more detailed to explain what the code is for.


The problem you mentioned regarding the 'Multiple field values on a single map' formatter is unrelated to this issue. It seems that formatter doesn't work properly in general at the moment.

rooby’s picture

Marked #999770: CCK Location field doesn't appear in views as a duplicate of this issue.

rooby’s picture

Re the problem regarding the 'Multiple field values on a single map' formatter. See this issue - #841340: Location CCK and Multiple field values on a single map

Status: Fixed » Closed (fixed)
Issue tags: -location cck, -location cck views

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