Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
location_save should only return FALSE or the lid. However, it sometimes returns empty values. I haven't had a chance to figure out under what conditions- I suspect it has to do with whether or not a country already exists.
The code I was using that produced empty values was:
<?php
$location = array(
'country' => $form_state['values']['profile_country'],
);
$location_id = location_save($location);
?>
Changing this to the following fixed it:
<?php
$location = array(
'country' => $form_state['values']['profile_country'],
'is_primary' => 1,
);
$location_id = location_save($location);
?>
This was quite a devilish error because setting locations on fields like this would throw SQL errors...
<?php
$profile->field_profile_address[LANGUAGE_NONE][0] = array('country' => $form_state['values']['profile_country']);
?>