When a location object is geocoded, the latitude and longitude don't end up in $node->locations. The problem is the for loop through locations works on a copy of the location information, and so when the geocoded information is added, it's added to the copy. This patch fixes it for me.

diff -u orig/location/location.module location/location.module
--- orig/location/location.module       2008-06-17 16:02:30.000000000 +0000
+++ location/location.module    2008-07-16 15:50:55.000000000 +0000
@@ -1014,7 +1020,7 @@
     case 'update':
       if (!empty($node->locations)) {
         db_query('DELETE FROM {location_instance} WHERE vid = %d', $node->vid);
-        foreach ($node->locations as $location) {
+        foreach ($node->locations as &$location) {
           $lid = location_save($location, TRUE);
           if ($lid) {
             db_query('INSERT INTO {location_instance} (nid, vid, lid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $lid);
CommentFileSizeAuthor
#5 location.module.patch1.42 KBbdragon

Comments

scottgifford’s picture

Title: Geocoded location isn't available to later modules in nodeapi » Geocoded location isn't available to later modules in hook_nodeapi

Updated title

scottgifford’s picture

Version: 6.x-3.x-dev » 5.x-3.x-dev

Oops, version was wrong.

scottgifford’s picture

That patch is incomplete, but I don't seem to be able to update the description for this bug. Here's an updated patch.

diff -u location/location.module location2/location.module
--- location/location.module    2008-06-17 16:02:30.000000000 +0000
+++ location2/location.module   2008-07-25 17:15:02.000000000 +0000
@@ -1014,7 +1014,7 @@
     case 'update':
       if (!empty($node->locations)) {
         db_query('DELETE FROM {location_instance} WHERE vid = %d', $node->vid);
-        foreach ($node->locations as $location) {
+        foreach ($node->locations as &$location) {
           $lid = location_save($location, TRUE);
           if ($lid) {
             db_query('INSERT INTO {location_instance} (nid, vid, lid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $lid);
@@ -1315,7 +1315,7 @@
  * @param $cow Copy-on-write, i.e. whether or not to assign a new lid if something changes.
  * @return The lid of the saved location, or FALSE if the location is considered "empty."
  */
-function location_save($location, $cow = TRUE) {
+function location_save(&$location, $cow = TRUE) {
   $oldloc = array();
   if ($location['lid']) {
     $oldloc = (array)location_load_location($location['lid']);
scottgifford’s picture

Title: Geocoded location isn't available to later modules in hook_nodeapi » Geocoded location isn't available to later modules in hook_nodeapi (patch)

Add note that patch is included.

bdragon’s picture

Title: Geocoded location isn't available to later modules in hook_nodeapi (patch) » Geocoded location isn't available to later modules in hook_nodeapi
Status: Active » Needs review
StatusFileSize
new1.42 KB

Isn't that a PHP5ism?

What about this?

bdragon’s picture

Of course, I forgot the & in location_save, but you get the picture.. ;)

scottgifford’s picture

Hi bdragon,

It looks like it is a PHP5-only feature, I didn't realize that. I will try out your patch and let you know how it works for me.

Thanks!

scottgifford’s picture

Yes, your patch seems to work fine!

bdragon’s picture

Status: Needs review » Fixed

Committed to DRUPAL-5--3 and HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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