Hello
When a user create a node I'd like to store his current geographical position into a geofield.
Maybe I could add the 'set my location' block on the node edit form, but how can I
- get the retrieved value from 'Set my location' ?
- store it in the proper format into my geofield ?
By code.
thx

Comments

artatum’s picture

I've tried the ip_geoloc_node module, which fits my need.

1st issue :
the ip_geoloc_node_form_node_form_alter is never called. :/
So I created another module and then it was fired. No comprendo.

2nd issue :
As no field was filled up, I started to debug the code, and I noticed that in line 41,

if (!isset($location['latitude']))

was always TRUE because $_SESSION['ip_geoloc']['location']['latitude'] doesn't exist ;
(we have : $location = $_SESSION['ip_geoloc']['location']; on line 25)
BTW I dont see where it could have been set : $location has got only 3 elements, none is called ['latitude']
It looks like my $_SESSION is not always good :/

3nd issue :

After a while, I only got
Fatal error: Unsupported operand types in .../form.inc on line 1808
when creating a new node.
I cant understand what is going on...
WHy my $_SESSIOn is always bad, although my modules are pretty ok on other pages (I can locate my anonymous user and display myfield_proximity in my views.)
But on the node page nothing work:/
Any advice is welcome.
thx for reading.

artatum’s picture

Well : I was trying to test the things on the body field :/ A matter of types... Sorry.
But new concerns. I'm trying to store lat/lon like in ip_geoloc_node module;
in my mymodule_form_node_form_alter I do :

function mymodule_form_node_form_alter(&$form, &$form_state, $form_id) {
...
  if (!isset($_SESSION['ip_geoloc']['location'])) {
        return;
    }
    $location = $_SESSION['ip_geoloc']['location'];  
    $latitude  = $location['latitude'];
    $longitude = $location['longitude'];
 $form['field_latlon']['und']['0']['lat']['#default_value'] = $latitude;
    $form['field_latlon']['und']['0']['lon']['#default_value'] = $longitude;
}

And though my latitude and longitude are there, nothing is saved on submit, hence my geofield is empty.
I've tried with WKT also( $form['field_latlon']['und']['0']['geom']['lon']['#default_value']=...), but the fields remain empty...
Could you help me please ? What did I miss ?