Is it possible to use this with the addresses CCK module?

cookiesunshinex - August 19, 2009 - 11:48
Project:Embed Google Maps Field
Version:6.x-1.2
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm already using the Addresses CCK module and wonder if a map can be generated from the address fields.

#1

andreashaugstrup - August 21, 2009 - 08:11

This is not currently possible, but patches would be accepted.

#2

andreashaugstrup - August 21, 2009 - 08:12

The best way to do this would probably be to create a CCK field formatter in embed_gmap module that works on CCK address fields.

#3

basanta86 - August 22, 2009 - 14:42

I was also trying to do the same thing as cookiesunshinex, here's my solution:

http://www.basantathapa.de/a-simple-embedded-google-map-with-address-fet...

#4

cookiesunshinex - August 25, 2009 - 12:25

basanta86 - Your simple fix does work only if you have a custom Street CCK field, custom city CCK field, but it does not work with the Addresses module.

I tried using my field names for the addresses - field_shopaddress_street and field_shopaddress_city

I even tried field_shopaddress, but nothing works. It seems like for some reason that the value returned is NULL when trying to use these fields.

Any ideas?

#5

basanta86 - August 26, 2009 - 10:43

Yes, you're right, I didn't use the Address CCK, but this should work somehow along the lines of my solution.

I suppose the problem is that the values of the Address fields are not stored in the same array as custom fields are.

You might try inserting print_r($node) in your node's template file to have a look at the arrays (and their structure) available for your node. If this doesn't work, I suggest digging into the Address CCK module and finding out where and how the values are stored.

#6

cookiesunshinex - August 30, 2009 - 15:53

How would I translate this:

[field_shopaddress] => Array ( [0] => Array ( [aname] => [street] => IFC Mall, Central, Level One, Shops 1041-1049 [additional] => Central [city] => Hong Kong [province] => [country] => hk [postal_code] => [is_primary] => [phone] => [fax] => [view] =>

into something like this that actually works?
$street = $node->field_shopaddress[0]['value'];

or
$street = $node->field_shopaddress[street]['value'] + $node->field_shopaddress[additional]['value'] + $node->field_shopaddress[city]['value']

I've tried both of the above without success.

I am confused by what seems to be an array inside of an array. (I'm just getting my hands dirty with PHP).

Perhaps, I'm just formatting the array reference incorrectly??

#7

basanta86 - August 31, 2009 - 10:11

Those arrays in arrays also confuse me a lot, but to explain the pattern as far as I understand it:

In the print_r-view, [something] is the key for the single array field which can either hold a single value, indicated by " => blabla" or another array, which is indicated by " => Array (".

When calling those values, the pattern looks like this $node->first array[key of field inside first array][key of array field if first field is an array].

I hope I got that right, since I figured it out by fiddling around with it as I couldn't find a proper documentation for this.

So, in my understanding, your call should look like this: $node->fieldshopaddress[0]['city'] (to get the city value)

Let me know if it works :D

#8

cookiesunshinex - August 31, 2009 - 13:30

Thanks so much for your help. It works!

To make sure that I had it working right, I used the this line of code at the very bottom of my node.tpl.php file

<?php print_r($node) ?>

Then in my dynamic field, I used an echo statement to display what was being outputted; with the givens that field_shopaddress is my custom CCK fieldname for Addresses module, and $gmapstreet, $gmapadditional, and $gmapcity are variables that I made up to pass to google's URL.

$gmapstreet = $node->field_shopaddress[0]['street'];
$gmapadditional = $node->field_shopaddress[0]['additional'];
$gmapcity = $node->field_shopaddress[0]['city'];
echo $gmapstreet . ", " . $gmapadditional . ", " . $gmapcity;

So to use the addresses field with your tutorial example to dynamically create a google map, here's the code.

$gmapstreet = $node->field_shopaddress[0]['street'];
$gmapadditional = $node->field_shopaddress[0]['additional'];
$gmapcity = $node->field_shopaddress[0]['city'];
return "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"http://maps.google.com/maps?f=q&amp;source=s_q&amp;geocode=&amp;q=".$gmapstreet.", ".$gmapadditional.", ".$gmapcity."&amp;ie=UTF8&amp;z=16&amp;output=embed\"></iframe>";

Maybe you can add that to your tutorial in case other people are using the addresses module.

NOTE: I may just use custom CCK fields for each address line instead of the addresses module since it seems that it's not supported so well and not that flexible according to what I read in the Addresses module issue queue.

 
 

Drupal is a registered trademark of Dries Buytaert.