Does anyone know if it's possible to assign a node a location (zipcode or city/state) automatically by pulling in the location of the author?
I want to group posts of my members by location. I can put the location fields in the node form, but would be simplier and easier for users if it just grabbed the info from their profile.
Any help or guidance would be appreciated.
thanks.
Comments
Comment #1
b__f commentedIf you have a module, you can use form_alter to alter a form with the specific form id you are looking for. Use a query to look up the location of the user. Then, you can access the $form structure and set the #value entries before the form is rendered. (This would require a bit of coding).
Comment #2
csc4 commentedThis gave me an idea - how hard would it be for the lat/lon to default to the users lat/lon if defined?
We have a multi-national site but typically people enter information about their locality so a site default is less useful than a personal one.
Comment #3
pshadow commentedYes, that is what I am trying to do. A zip code or lat/long based on author (user's) location as defined in his profile, not his current physical location. I'll look into B__F suggestion. If you come up with anything csc please post. thanks.
Comment #4
jamesJonas commented+1
take lat/long from author
or take from group
or take from site
These types of cascading locations would be very helpful. The downside is that last I checked, location ignores geocoding if the lat/lon is filled in. This means that if you push to lat lon to early, if the user inputs an address for the post, which may represent an even more relevant location, that addresse's geocoded lat lon may be ignored.
Comment #5
ju.ri commentedthis would be great! I already suggested this a while ago : http://drupal.org/node/131878
I'm sure it would be useful for many sites.
a similar way to do it might be to add "author location lat./long." fields to the views part of the module. that way we could at least pull the data to create maps and lists of nodes with their authors' locations.
btw: there is already an author location block in gmap.module
http://drupal.org/cvs?commit=66486
Comment #6
catchSimilar request for image.module exif data: http://drupal.org/node/172646
And another duplicate with some 'nasty hack' suggestions: http://drupal.org/node/131878
Comment #7
sgdev commentedUsing
hook_form_alteras b__f suggests in post #1 would make sense in most situations, but the Locations fieldset is not exposed as part of $form. I have a module where I runmymodule_form_alter, and in this function I've done aprint_r($form);. Nothing in regards to the Locations fieldset is shown.Unfortunately, the one option that will work is a variation on the 'nasty hack' suggestion in post #6. It does not work in Location 3.x as shown here. Instead, the following needs to be done --
In the
location_formfunction inlocation.module, add the following two lines after the first conditional:Further in the same function, when in the
forloop, make the following changes:If anyone has a better suggestion, or has some way in which form_alter will work, I'd definitely like to hear about it.
Comment #8
yesct commentedtagging with something slightly related.
Comment #9
sgdev commentedI'd like to mention that I have further customized what I mentioned in Comment #7. We are using Organic Groups (og), and when a new calendar event is added to the group, we decided to auto-populate the location with the Group location rather than the User location. This makes sense for us because in most situations, an event will happen at or near the Group location.
This involves a modification to the code in Comment #7 to load the location of the group rather than the user if the current node is an event.
Comment #10
yesct commentedtagging.
Comment #11
farald commentedron_s, regarding #9, could you post the code for your modification?
I need to do exacly the same thing, so id be very interested to have a look at it.
Thanks:)
EDIT: Nevermind, got it working:)
Comment #12
yesct commentedhamaldus, Could you post your steps you took to get it working?
Comment #13
farald commentedIt was a quick hack of ron_s' version.
I need to be able to create nodes with lat/lon inherited from previous node.
If no node to inherit from, the location needs to be set at the user's location (users only post nodes to their immediate area)
The easiest way is to check for a node id in arg(3) after node/add/nodetype/ to inherit from.
Then I used the last part of ron_s' hack in #7.
It seems to me that it would be relatively easy to implement this to location.module by using something like this following pseudo:
It would also be best if it was possible to edit inherit settings at a per-nodetype basis.
Comment #14
sgdev commentedhamaldus, it's slightly different if creating a node which is related to an Organic Group. There needs to be the added aspect of recognizing in which group the user is currently located. This can be found in
$_SESSION['og_last'].So I modified the first half of the code as follows:
The first conditional is new. I added
arg(0) != 'user'to skip the location pre-population if in the user profile. This addition is important, otherwise an admin who makes a change to a user profile with no location will have their location (the admin's) saved as the user's location.The second conditional says if adding a group node, and the group node is a calendar event, then check to see if the
og_lastsession variable is set. If it is, use it to get the location of the group. Otherwise, use the user's location.Comment #15
spidersilk commentedI tried applying the changes ron_s posted in comment #7, and it initially didn't seem to be working - until I realized I'd set the location in the wrong place!
So, for anyone else using the Content Profile module with this, you need to make sure that the user's location is set in the core profile (the part under Edit > Account), not just in the content profile!
Comment #16
ankur commentedLooks like this support request has been serviced.
Comment #17
rickharington commentedHey guys, I'm sorry to post on a closed thread, but don't want to add to the existing issues. Is this still applicable in 7.x? Should I create a new thread?