Hi,
Am I correct that the location mapper is not yet on the mapper-2-branch?
Thanks for your answer in advance.

greetings,
Martijn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Aron Novak’s picture

Status: Active » Fixed
Summit’s picture

Does it work on cck_location or location native?
I am not getting it to work?

Did: Add cck_location field to feeditem nodetype
Did: set feeditem nodetype as parser "export" nodetype
Did: set in feeditem nodetype location to 1

But nu location_mapper in MAP area of the feed..

Thanks a lot for your reply in advance!
greetings,
Martijn

Aron Novak’s picture

Category: support » bug
Status: Fixed » Needs review
FileSize
848 bytes

Thank you for reporting more information.
This is definitely a bug, unfortunately. Here is a patch.
Can you test it?
If it works for you, feel free to set the patch to RTBC.
Unfortunately the location is the only mapper without any tests, i'd bet this is the root of the bug here.

Summit’s picture

Hi Aron,
Will try to test this evening, thanks for your quick response!
greetings, Martijn

Summit’s picture

Hi Aron, it is working now, thanks!
Why not mapping for all fields available?

Altering:

$sub_fields = array('latitude' => t('Latitude'), 'longitude' => t('Longitude'));

To:

    $sub_fields = array('latitude' => t('Latitude'), 'longitude' => t('Longitude'), 'name' => t('Location name'), 
                                          'street' => t('Street location'), 'additional' => t('Additional'), 
                                          'city' => t('City'), 'province' => t('State/Province'), 
                                          'postal_code' => t('Postal code'), 'country' => t('Country') );

Is sufficient for this, right?

Greetings,
Martijn

stevestaso’s picture

FileSize
28.48 KB
33.05 KB

After updating to 6.x-2.x-dev, the location mapper doesn't show up unless I add a CCK location field.
At the bottom of the Map tab:
Instead of the location mapper, I now see a mapper for feedapi_node module.?.
See attached.

I verified the same items in #2.
I added the patch in #3. Still no joy.

If I add a CCK location field to the feeditem nodetype, upon saving - I get an error for each item in the list (as attached)
I use the csv parser and the FeedAPI Node processor.

Other elements map OK.
But I can't get the location elements to map to the node's location fields - CCK or native.
(I added subfields like #5)

I've also tried the 6.x-1.0 version.
That shows the location mapper listed at the bottom; I mapped some location elements, but the mapping never occurs.

Any guidance on how to troubleshoot this?

Thanks in advance.
steve...

Summit’s picture

Hi,
Any progress in this field please? Is the location_mapper working now correctly?
And will it also work on location AND cck_location, or only the cck_location in the future?
Thanks for your reply in advance.
Greetings, Martijn

nicholas.alipaz’s picture

Title: Location mapper not on 2-branch? » Location mapper no longer working.
FileSize
3.6 KB

The attached file was written with the 2.x branch.

I am attaching the work I just recently did on this for a site I am working on. It works to get mapping a source to a target location enabled node.

Some things to note that will likely still need work:

  • This solution only fixes it to map to 1 location.
    I did not code it to work for multiple locations, since I didn't need it for this site, I am sure someone else can make it work with multiple.
  • I have not performed any checks for whether locations are enabled for the node type that the fields will map to, so I am not sure what happens if the content type doesn't have locations enabled.
  • This does not work for cck location fields, only the location fields provided by a content type that has locations enabled for it.
  • I am not extremely familiar with the hook_feedapi_mapper() function, so some of my code could be a bit strange

The overbearing issue that seems to have caused this mapper to break is that the location module seems to be requiring that we send it an array with all values of the array filled in. I am not sure if this were the case in prior version of the location module. I found that if I tried to just send latitude and longitude or anything less than the full array the values were not inserted into the mapped fields. This occurs even if you set some of the fields to "not collected" in the content type. However, you can send empty strings instead.

* normally I would send this as a patch, but it is a complete rewrite so I am just attaching the file here.

Summit’s picture

HI, this mapper (http://drupal.org/comment/reply/559744/2045510#comment-2045510) let me see the location mapper again.

I got this error now.

warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /httpdocs/includes/database.mysqli.inc on line 323.

EDIT: I found the problem. In the attachment there is the line

      $node->locations[0]['feedapi_temp']['feedelem'] = $feed_element;

This needs to be:

      $node->locations[0]['feedapi_temp']['feedelement'] = $feed_element;

Still no success though with the mapping, yes the fields show, but how to map correctly?

greetings,
Martijn

Any suggestions please?

greetings,
Martijn

nicholas.alipaz’s picture

This version of the file will only map to the default node elements in the node. They cannot be mapped to cck fields. Are you using the node elements provided by the location module? Can you describe in more detail what you are doing/what is happening?

Maybe even a screenshot of your mappers and the content type you are mapping to would help. Also what version of the location module, feedapi_mapper, and feedapi?

nicholas.alipaz’s picture

What you changed in your previous post should not be necessary and is very unlikely to fix that error. Seems to be a coincidence.

Summit’s picture

Hi,

Your question: They cannot be mapped to cck fields. Are you using the node elements provided by the location module? Can you describe in more detail what you are doing/what is happening?

I use location (not cck_location) as you described.
I would like to map a rssfeed with category fields filled with geographical information mapped to the location info in the node:

<category>NL</category>
<category>Nederland</category>

These values needs to be mapped to:
-"NL" -> Location $country (country_code)
-"Nederland" -> Location $country_name (country_name)

It seems that location is not working without using proper isocode and countryname, right?

Thanks a lot in advance for your assistance.

Greetings,
Martijn

nicholas.alipaz’s picture

Yes, in my testing you must provide the proper countryname to the appropriate field, or leave it blank will work I believe. But if you send it incorrect info then it will most certainly not allow any fields to fill in.

As stated in comments in my code,

      // for some reason location module will only except a complete array for these values now, so we construct the entire array here
      // we also run all mapped values through the feedapi_test_location_var function to keep from overwriting prior set values

So leaving a field "empty" is ok, but if you fill it in with incorrect info then it will cause all other fields not to get filled in since it requires a full array to be submitted. One wrong field breaks the mapping on all others in my experience.

Further testing by others would certainly be of use in getting a working version of this mapper.

Summit’s picture

Hi,
Is by your testing it enough to send the country_code ($country)? Or needs location country_code AND countryname? I am not able to get a location record filled through the mapper.
And do you know how to map fields which are in a array in the rss, like category[0] and category[1]?
greetings, Martijn

nicholas.alipaz’s picture

I have not tested with arrays. Merely with a single value to a single field. Seems there is a lot to be tested here. On your install I would attempt testing with basic values first and see if it works, then proceed to make it more complicated. If you can't get a basic implementation to work with this, then the arrays and such are most certainly not going to work.

Summit’s picture

Hi,
I think this post is relevant about location field mapping I think: http://groups.drupal.org/node/27864
Especially:
# When solving 1 and 2 the locatiomodule will still attempt to find ‘better’ coordinates and throw away the provided onces

# The location module will not produce georss information for fields stores in ckk ( and the mapper stores in ckk only)

Greetings,
Martijn

Yorgg’s picture

I have updated to 6.x-2.0-alpha3 and location cck or geo field mapping are still not available although.
By nicholas.alipaz @ #8 rewrite fields are now available and seem to be working via cck, or did I made the location node enabled in the background?

I can see longitude and latitude on the node teasers but not on the cck itself.

Summit’s picture

Hi my update:

I now have got a nicely rss feed to be able to map within feedapi, feedapi_mapper, location scope.
It has all fields necesseray for mapping I think: georss: lat, lon, isocode in lower case for country isocode. But nodes will through mapper not be filled with geo (location) info...

greetings, Martijn

Summit’s picture

Hi, #10 (remark from author #8) says clearly it is NOT working through CCK..

Summit’s picture

Hi Aron,

Patch from #3 was NOT committed to alpha 3. Will you get it in within alpha 4 please?
Next to this my findings are that somehow location_mapper does not map location information with a negative latitude.
Record with the following is mapping correct:

<georss:point>19.8562700 102.4954960</georss:point>

Record with the following is NOT mapping correct:

<georss:point>-30.5594820 22.9375060</georss:point>

Thanks for committing the #3 thingie already!
Greetings,
Martijn

Summit’s picture

Hi,
How can I debug what is coming out of the location mapper. I am in the blind now :(
I would love to see what array goes out to be mapped to nodes:)

EDIT: drupal_set_message is my friend!

I had it working, but where can I find feedapi_test_location_var()
Now it says: Call to undefined function feedapi_test_location_var()

EDIT: still can't find this function, could you atrach it to your reply please?
Thanks a lot for your reply!
Greetings,
Martijn

Summit’s picture

Hi,
This is a version of feedapi_mapper_location which I am working with right now:

<?php
// $Id: feedapi_mapper_location.inc,v 1.2.2.2 2009/08/07 15:43:43
aronnovak Exp $

/**
 * On behalf implementation of hook_feedapi_mapper() for location module.
 *
 * @see hook_feedapi_mapper()
 */
function location_feedapi_mapper($op, $feed_node, $active_processor,
$node = NULL, $feed_element = array(), $field_name = '', $sub_field =
'') {

 // Checks processor compatibility.
 if ($active_processor != 'feedapi_node') {
   return;
 }

 if ($op == 'describe') {
   return t('Maps pairs of geographic coordinates to the location of a node.');
 }
 else if ($op == 'list') {
   $sub_fields = array('latitude' => t('Latitude'), 'longitude' =>
t('Longitude'),
   'name' => t('Location name'), 'street' => t('Street location'), 'additional' => t('Additional'),
   'city' => t('City'), 'province' => t('State/Province'), 'postal_code' => t('Postal code'),
   'country' => t('Country code'), 'country_name' => t('Country [full name]'));
   $info = content_types(feedapi_mapper_get_item_node_type($feed_node));
   $fields = array();
   if (@count($info['fields'])) {
     foreach ($info['fields'] as $field_name => $field) {
       if (in_array($field['type'], array('location'))) {
         $fields[$field_name] = $sub_fields;
       }
     }
   }
   if (count($fields)) {
     return $fields;
   }
   return FALSE;
 }
 else if ($op == 'map') {
   if (is_array($feed_element)) {
     foreach ($feed_element as $i => $val) {
       $node->{$field_name}[$i][$sub_field] = $val;
       if ( $node->{$field_name}[$i]['latitude'] ||
$node->{$field_name}[$i]['longitude']  ) {
            //Set the inhibit_geocode to TRUE because the feed already has lat/lon. 
            //Location does not need to touch these feeditems then.
            $node->{$field_name}[$i]['inhibit_geocode'] = true;
       }else{
            $node->{$field_name}[0][$sub_field] = $feed_element[0];
       }
       drupal_set_message($node->{$field_name}[$i][$sub_field]);
     }
   }

   return $node;

 }
}
?>

The else is not working correct yet:
$node->{$field_name}[0][$sub_field] = $feed_element[0];
And the feeditems which have correct countrycode (isocode) and lat/lon will get somehow the standard isocode and not the one which is also already in the feed..

But may be this version is also a great improvement for the discussion to get a good working feedapi_mapper_location which works for cck_location (this version does) and also location (this version does not).
Great improvement of this version is the stuff to not use geocode of location if georss already in feed. Great problem is isocode still..

greetings,
Martijn

flamingvan’s picture

FileSize
2.91 KB

I've made some modifications to nicholas.alipaz's mapper for native locations. His originally didn't work at all for my installation, so I fixed it and then I made it capable of mapping to multiple locations. I hope this will be helpful to someone.
Location version 6.x-3.1-rc1
Mapper version 6.x-1.0

Summit’s picture

Hi, Would be great also have location_mapper on feeds, because feedapi will go away..
Greetings, Martijn

nemchenk’s picture

FileSize
2.92 KB

I had to edit #23 a little bit to get it to work for me, basically changing line 79 to be "for($x = 1; $x < $num_locations + 1; $x++){". I also replaced all the tabs with spaces, and sorted out some of the indentation and blank lines.

I enclose the whole file as a patch would be too confusing because of all the indentation changes. This works for me with Location 6.x-3.1-rc1, FeedAPI 6.x-1.8, and Feed Element Mapper 6.x-1.3.