I've gone through the code in modules/all/location/contrib/location_cck but am unable to figure out where this CCK field is storing the address data.

I guest that it's install file should have table fields to store geographic data like city, lat long etc. But it isn't there.

Edit: Ultimately I want to access all those location fields separately(beyond Views) when writing modules etc. For example I want to read postal code attached to a particular node for some analysis. That's why I'd like to extract location info about nodes.

  • I already answered this here: drupal.stackexchange.com/a/16284/633. – Andy Nov 29 '11 at 10:38
  • ...but I could still not figure out answer to this. – AgA Nov 29 '11 at 12:37
  • then I think it would be better to ask on the existing question, rather than create a new one personally. – Andy Nov 29 '11 at 13:03
  • Sorry, but this question wasn't the main theme of my last question which you answered. Starting long discussion like here would have looked a misfit there. – AgA Nov 29 '11 at 13:20
  • 1
    Andy, I'm sorry for this. Not only for this or the last one, you'd satisfactorily answered my questions sometime back too. I accept my mistake for not mentioning link to this question. Next time I'd take care this.. – AgA Nov 29 '11 at 13:36

As mentioned, the data's stored in the location table, which is handled by the location API and indexed by location ID (lid). The CCK field stores an lid. If you have access to the node object with the field, then you can access the address fields directly from the node object. If you don't have the node object and want to avoid the cost of loading lots of nodes, you can get the CCK DB details using content_fields($field_name, $content_type_name) and content_database_info($field). Then you can use location_load_location($lid) to get the location. I've just taken a quick look at the source for location_load_location() and note that it might do JIT geocoding (so it might actually write as well as read!). I imagine you won't have any issues with doing a join directly on the location table, but I always prefer to use the API where possible.

There's also the command location_load_locations($id, $key) which looks like it can give you all locations associated with a particular nid or vid, but I don't think that's what you're after.

  • Looks like this is what I'm looking for. I'll first go through these functions to understand it fully. – AgA Nov 29 '11 at 18:10

Most CCK field modules let the CCK take care of creating tables and fields and saving data. This is done by implementing hook_field_settings().

  • location_cck is slightly atypical in that the field itself stores only an ID into location.module's table. – Andy Nov 29 '11 at 13:04
  • I'm guessing but not sure if I'm correct: Location is stored in location table with key lid, then this info is linked to node using nid,lid in location_instance table . – AgA Nov 29 '11 at 13:23
  • @AgA CCK stores an LID as the field's data. This is sufficient to do the look-up from the location table. I don't know what location_instance is for. – Andy Nov 29 '11 at 13:36
  • How to query location data for a particular node using drupal_query? I think I need to join location_instance and node tables on nid to get lid then use it with location table to get the location data. – AgA Nov 29 '11 at 13:40
  • @AgA can you edit your question to explain in a bit more detail what you're trying to do? (Eg. where is this code running, what's its final goal?) Direct DB queries might not be the best way to achieve what you want. – Andy Nov 29 '11 at 15:12

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.