How do I display a GMAP for a Location CCK field ?

jasontanner - February 28, 2009 - 17:45
Project:Location
Version:6.x-3.1-rc1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

Hi Guys,

I'm sure it's me and I'm just missing something ... but ...

I'm trying to get a GMAP to display in a block for a node that is using Location CCK but its just not happening.

So, I have a node type Business, with a CCK Field called Address of Type Location. That parts works well, the address details are collected on entry and appear to be being geocoded.

But, then I want to show a Block with a GMAP in it for the CCK Field called Address.

I thought that the "Location map" block would answer my needs but is doesn't - I'm guessing its only intended for the non-cck Location stuff.

So, how should I be trying to get a GMAP to display for my Location CCK Field ?

Jason

#1

jasontanner - March 4, 2009 - 22:55
Project:GMap Module» Location
Version:6.x-1.x-dev» 6.x-3.1-rc1

Moving this to the location project as I had no response from the gmap one, bumping version as well.

#2

michaelfavia - March 4, 2009 - 22:57

We are still working on views support for the cck field based locations. Help is welcome. You can see our efforts in the issue queue. Alternatively you can use the location_node.module for your locations if you dont want to wait/help and you can still use views.

#3

jasontanner - March 4, 2009 - 23:52

Hi,

Thanks for the speedy response. So, I take it from your reply that the way to display a GMAP for Location CCK will be via a View but currently thats not available. I'm happy to help with any testing. I'll have a hunt for the issues thread and keep an eye on it. I'd prefer to go the cck route so will hang on for location cck / views integration to be come along.

Thanks again.

Jason

#4

andybounce - March 17, 2009 - 19:36

I might be in over my head here, but I have something setup on a current project that appears to be exactly what you're talking about. Currently it's a mix of GMap + Location cck + content profile + Views.

Currently the goal of the map is to display all of the dealers for a certain company on a map. These dealers enter their addresses at registration, and the info is automatically ported into a new 'Dealer' node (via content profile). This information includes the dealer's address in Location cck form.

Assuming that all of your cck stuff is setup properly, here's the views scheme:

(Assume all items not listed are defaults)

View Type - NODE.
Style - GMap (defaults are fine, welcome to set your own macro)

Relationships - Content: Location (the one from the Dealer node)

Fields:
- Content: Dealership Name (the name of the dealer, to be displayed in GMap bubble)
- (Location) Location: Latitude (must set relationship to "Location". This yanks the info from the Dealer nodes. Also check "Exclude from Display" to hide it in the bubble).
- (Location) Location: Longitude (again, must set relationship to "Location").
- I also have added Address and Phone number, with relationships set to "Location" for inclusion in the GMap bubbles.

Filter:
- Node: Type = Dealer (Relationship not required).

And that's it! Aside from adding a Page view to display the map, I didn't do anything extra. Apologies if all of this is rather obvious and I just missed the point of the question :)

#5

YesCT - March 23, 2009 - 13:21

Are you sure you are using the location cck field in your dealer node? Could you post a screen shot of the node edit fields so we can see the settings there?

Also, maybe you could "export" the view you created and post it here too?

Thanks a ton.

#6

HelluvaEngineer - March 26, 2009 - 23:53

What do you mean by the last part - add a page view to display the map. Is another view required or is this something we wire up in the content type? Sorry if this is a stupid question.

#7

tonycpsu - April 3, 2009 - 18:46

Subscribe

#8

orianasarac - May 14, 2009 - 23:10

#4 thanks for spelling it out! your steps were very useful. there is one more thing i needed to do, so i am adding it here:

style GMap: make sure you select "choose long/lat fields" for data source under style options, and select latitude and longitude fields bellow. (my default was Location.module)

i spent *endless* hours trying to figure it out, and i finally got it to work. hope this helps others.

#9

mrgoltra - June 11, 2009 - 16:17

subscribing

Is it possible to filter by NID just to show the address associated with that node? I have added a NID filter and tried is equal to $NID and %NID but can't get it to work. I am I doing it correctly?

Thank you,

Mark

#10

drew reece - June 12, 2009 - 16:52

I think you need to use an argument mrgoltra.

I'm trying to achieve the same using the Views attach module. But I can't figure it out. I have a node displaying all the other cck_locations that exist for that content type, attached to the node view. I just want the one location that is assigned for that node.

You may find something that helps in the 'advanced help' for views, you'll need the advanced help module.

#11

mrgoltra - June 12, 2009 - 18:20

Thanks Drew,

No problems showing all the cck_location but in this case I just like you I just want to show one location. I assumed that if you filter it by Node ID, it should work but when I do, the map doesn't show up at all. I read about Views attach and tried it, but no luck as well.. I did look at the advance help and not much info.

Not much familiar with arguments. Will read up on it.

Back to the drawing board.

Thanks,

Mark

#12

drew reece - June 12, 2009 - 20:23

Mark,

I seem to have managed to get it to work. I now have the standard node view with an attached Google map.

I added an argument to the view, selected Node:Nid as the argument type.
Change the following settings for the argument.

Action to take if argument is not present: Provide default argument
Provide default argument options: Node ID from URL
Everything else as default.

I don't know how you are trying to get the map to show on a node, I guess you are using a view with some attached views? I suspect we have a lot of different methods to achieve this, I can post a views dump if you require it.

I did need to use 2 patches because views_attach wouldn't read the NID correctly -
Token data not passed to argument comment #60
and location made errors when the display was shown -
Array errors in location_cck module comment #5

It was this post that got me to try views attach
http://groups.drupal.org/node/23030#comment-80112
I think it was this screencast that got me to understand views attach
http://www.lullabot.com/articles/photo-galleries-views-attach

#13

mrgoltra - June 12, 2009 - 21:35

Drew,

That is great to hear. Thanks for the heads up. I did apply the location_cck patch but not the token data. Yes I am trying to get a map to show that is associated with that node.

If you don't mind I would appreciate a view dump.

thank you,

Mark

#14

drew reece - June 12, 2009 - 22:41

I have attached the view…

I don't know how well the import sets up the required content types & fields so here is an outline of my setup.

'Event' content type with a Location CCK field called field_location_event. The type is not from Calendar or Event module.

Modules (names taken from admin/build/modules)
Gmap 6.x-1.1-rc1
Gmap Location 6.x-1.1-rc1
Location 6.x-3.1-rc1
Location CCK 6.x-3.1-rc1
Views attach 6.x-2.0
The patches mentioned above.

I think you will need to check in the 'Node content' view the type to set it to use the cck type you have setup with location_cck. Try cloning & tweaking from the import.

If it works you should end up with a title 'Attached VieW' at the bottom of the node page. Try changing the default view to a table to see fields that should be passed to the gmap plugin. I think the key part is that the GMap style gets it settings via the relationship to the location_cck field.

I wish I understood it better :)

Drew

AttachmentSize
event-view.txt 6.76 KB

#15

mrgoltra - June 12, 2009 - 23:21

Thank you. Very grateful for this will give it a shot.

#16

mrgoltra - June 13, 2009 - 07:16

Drew,

Thank you very much, that really helped. What I did wrong was not including the NID in the Fields.

Mark

#17

drew reece - June 14, 2009 - 02:11

Great, I wasn't sure I needed the NID in the fields :^)

#18

macuhail - June 14, 2009 - 16:03

Great info. Thanks for sharing this.

#19

izmeez - June 20, 2009 - 18:08

Thanks very much for sharing these thoughts. On re-reading this thread I can see it's all laid out and I was just restating the problem, unnecessarily.

Izzy

I am having the same problem, I created a new content type with cck and created one field as a location field. It works fine and collects the data and in the display provides a Google gmap link that works fine. But, the item does not show on the Node locations display. If instead of using a new cck field of location type, I edit the content type to allow locations for the node, it works to both permit collection of the data and display on the Node locations display. Unfortunately, this does not give the ability to name the field as needed. Also, it is not possible to move the location collection field to where ever you need.

#20

mrgoltra - June 15, 2009 - 23:56

Izzy,

It will work using views. Follow # 4 . You will need to create a page view and set the style to gmap. Then you will need to add the location (lat and long) in the field and set the filter to publish yes and select the node type. You will need to add the relationship described in this post.

Hope that helps. You might need to play around with the settings to get it to work. Good Luck

Mark

#21

izmeez - June 21, 2009 - 03:50

Thanks. I used comment #4 and #8. Worked great.

Now, is there a way for views to determine gmap settings, such as dimensions, auto zoom or not, and possibly the other gmap default settings then the gmap display would be unique for the view and it would be possible to also create a block view and different views for different group types? This would be really cool.

Thanks,

Izzy

#22

drew reece - June 21, 2009 - 13:21

@ izmeez,
Edit the view, select the Gmap style settings by clicking the 'gear' next to where it says Style:Gmap in the Basic settings.

Add whatever you want to the macro, turn on the builder module to get an idea of possible values, & output options.

eg [gmap zoom=16 |behavior=+autozoom]

Rinse & repeat for other views.

#23

izmeez - June 21, 2009 - 17:37

Thanks very much, I'll give that a try.

Meanwhile, I decided to add a block view anyway to display the map on the front page or any other page.

The items to display is unlimited to show all points on the map thus the more link for the block view is not visible.

So I used a tip shared elsewhere in this amazing Drupal community to use the Views header or footer and entered a simple html link. It could be a link to the page view or a link to something related.

Thanks,

Izzy

#24

drew reece - June 21, 2009 - 18:36

Izmeez,
You probably know this already, but it's worth repeating.
If you are showing all nodes in a view, add a filter to prevent unpublished nodes showing up to anon users. I think views 2 may warn you if this is not the case. The 'admin or published' filter option is handy to let the admins see the unpublished & published stuff in a view.

#25

izmeez - June 21, 2009 - 19:41

Yes, I've been using the 'admin or published' filter option. It is a good reminder for those new to using Views.

Izzy

#26

izmeez - June 21, 2009 - 23:35

Drew,

Thanks very much. Works great for creating different views. I now have a mini block for the sidebar and a larger block for the content area of specific pages, be it the front page or something else.

Unfortunately, all the settings are not available yet. Maybe this is a function of the Gmap macro builder, maybe I should add this to the GMap issue queue as a feature request.

The settings for auto zoom are not available.

It also looks as though the options for the size of google maps menu items is limited to small where something even smaller would be handy for a sidebar map.

Thanks so much, all of you.

Izzy

#27

izmeez - June 22, 2009 - 00:33

Now, everything seems fine but some of the content being created is not showing up on my views maps while others are. There even seems to be a difference in which one's are showing when logged in or not and the nodes are all published. I'm not sure if it's a buffer thing or some error.

When I look at the nodes they have an address and they show a Google map link which works.

Interestingly, the ones that show on my views map are only showing on the linked google map as one pin which when I click gives just the street, city, postal code; whereas one that doesn't show on my views map the google map link shows many pins and clicking on each gives more info as if it is part of google's own database. So, I'd like to be able to solve this.

I would also like to be able to find a setting to make the info show when the mouse hovers over a pin, if that is possible.

Sorry, to be asking so many questions here. I hope it's okay, please let me know.

Thanks,

Izzy

#28

drew reece - June 22, 2009 - 00:54

Izzy,

You should be able to add the automatic zooming feature by adding this to the macro used by the Gmap style view…
behavior=+autozoom
Add a pipe "|" between each setting.
I can't remember where I saw it, I think I found that the node locations map did it & then copied it from the macro it used. Gmap is not too well documented, I think it is partly the immensity of the options that causes it, combined with everyones idea of 'how it should work'. Try installing the advanced help module, it may help give you an idea what to try.

You can configure the markers in a similar way, but you need to add one to get the macro builder to create the code for it.
markers=small red or markers=alt small red

Make sure you search the issue queue if you do post, the developers seem quite busy on it. There is also this http://groups.drupal.org/mapping if you want to contribute in some way.

Good luck with it.

#29

izmeez - June 22, 2009 - 02:09

Drew,

Thanks again for all the help.

Now I may have an issue worth putting forward, but I'm not really sure which module issue queue it belongs in.

The Views, style, gmap, settings, macro field has a limited number of characters so I cannot add the extra settings I would like to.

Any thoughts on where I should place this issue?

Thanks,

Izzy

#30

drew reece - June 22, 2009 - 02:33

My best guess is Gmap, it seems to have views code within it's module. You could turn of the module to see if the views 'Gmap style' goes away, don't do it on a live site :) and have a DB backup just incase.

The visibility issue you mentioned could be permissions, make sure anon users can access the content type & the view.

The address in popup could be due to the fields in your view. I think you may not be referencing the Location field as a relationship in the view that has no (Googles own) address data, but I could be wrong. I found that temporarily turning the Gmap view style into a table helped to debug what fields were being found.

You could maybe clone the good view, then tweak that to show all the nodes and see if the popups remain as you want.

No idea about how to make it show info on hover, check the issue queue & post if it doesn't exist.

#31

izmeez - June 22, 2009 - 19:31

Drew,

The visibility issues turned out to be of three types:

1. User permissions needed to be better configured related to OG. Works fine.

2. Occasional points had incorrect postal code which did not match with the street address.

3. One point was clashing with other points in the Google database for that address with different postal codes. A different nearby address was needed.

Thanks for the tip to try a Views table view to debug. This was useful for a check but I think the Gmap macro is lost when you return to that style and look at it's settings so you may want to copy the macro to your clipboard first.

I am not understanding your suggestions regarding popup of info on mouse hover.

I do have a views relationship to the cck location field and I have specified under fields, "(Location) Location: Address" as well as latitude and longitude.

The items display fine on the map and the info shows up great when clicking the item on the map, it just doesn't automatically display if the mouse hovers over the pin. I'm wondering if this is a macro issue, a feature of Google maps 2 or 3-beta, or a feature request for the gmap module. Not clear yet.

Thanks very much.

Izzy

#32

kevin riggen - June 23, 2009 - 20:36

Cheers to you all for getting this info public.

I'm having an error when selecting Style - GMap in Basic Settings

"An error occurred at 'site'/admin/build/views/ajax/display/GMAP_TEST/default/style_plugin"

Anyone have any ideas on how to troubleshoot this?

*EDIT*

When I turn off Javascript on my firefox 3 browser, I get the following error when selecting 'GMap' and then 'Update'

"Parse error: syntax error, unexpected T_OBJECT_OPERATOR in 'site'/modules/gmap/gmap_plugin_style_gmap.inc on line 68"

*EDIT*

Here is line 68 of that file :

$lat_field = $this->view->display_handler->get_handler('field', $this->options['latfield'])->field_alias;

*EDIT*

Here is the whole entry related to line 68

// Determine fieldname for latitude and longitude fields.
if ($this->options['datasource'] == 'fields') {
$lat_field = $this->view->display_handler->get_handler('field', $this->options['latfield'])->field_alias;
$lon_field = $this->view->display_handler->get_handler('field', $this->options['lonfield'])->field_alias;
}

SOLVED

Switching form PHP 4 to PHP 5 solved my issues.

#33

drew reece - June 23, 2009 - 19:59

Do you have fields set up for the latitude & longitude? Are they fields that use a relationship to the location CCK field?
Can you try working from the view in #14, it can be imported as a basis to tweak. It seems to work for others.

#34

kevin riggen - June 23, 2009 - 20:37

Yes I had the latitude & longitude fields set up, and all other instructions from #4.

When importing the view in #14, I get the same error :

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in "site"/modules/gmap/gmap_plugin_style_gmap.inc on line 68

I have Javascript turned off under "Views - Tools" to rule out any possible issues that may cause.

SOLVED

Switching form PHP 4 to PHP 5 solved my issues.

#35

kevin riggen - June 23, 2009 - 20:39

SOLVED

Switching from PHP 4 to PHP 5 solved my issues.

Thank you Drew Reece. I'll probably be back ; )

#36

drew reece - June 23, 2009 - 20:51

Someone will probably experience this again, post an issue in the gmap queue, it should be mentioned as a requirement of Gmap in the README.txt.

#37

kevin riggen - June 23, 2009 - 20:59

done

#38

izmeez - June 23, 2009 - 22:20

Regarding the limited fixed field for entering the gmap macro in the Views>style>gmap>gears I did go ahead an post an issue, http://drupal.org/node/499136

Just in case it gets legs.

Thanks

Izzy

#39

mErilainen - June 26, 2009 - 06:48

I cannot get this to work.

Everything works fine before I enable argument. After adding Node: Nid as argument, the map doesn't load at all. I have tried including Node:Nid in Fields also. I'm using panels to build a profile page with map block in it, but it shouldn't make a difference.

Edit:
Uuups, forgot to choose relationship in the panel. Now I chose Node ID and it works like a charm.

#40

mrgoltra - July 6, 2009 - 23:48

from my understanding at this point, dev version should contain fixes.

I was using views attach but for some reason it stopped showing the map. Not sure what I did. Maybe an update caused my issue.

#41

rucx - July 18, 2009 - 08:45

nice, but how do i display only the marker of the current node instead of all nodes if using attach view?

#42

mrgoltra - July 18, 2009 - 09:12

I had to add NID in the fields section

#43

Golem07 - August 5, 2009 - 18:03

@#39
I am stuck at this part as well: As soon as I try to add an argument, the map will not show up anymore (views preview says: "no query was run"). Does somebody have a solution to this?

Furthermore I am not sure what you mean by setting the relationship in panels. I did add a relationship to my content profile. However, this alone doesn't seem to prevent that all markers are being shown on the content profile. When I try to solve this via the arguments setting in views the above happens.

#44

mrgoltra - August 5, 2009 - 18:11

hope this helps.

please see attached.

This is my current setup for AD content type.

AttachmentSize
node map.png 20.29 KB
node map 2.png 26.34 KB

#45

Bartezz - August 11, 2009 - 12:54

Thanx andybounce but especially orianasarac (for that last hint I needed).

Think I'm going to dump my girlfriend and marry this node/386848.... I love it SO much ;)

Cheers all!

#46

mrgoltra - August 11, 2009 - 15:43

thumbs up. I wish the site had the thumbs up icon put in.

#47

thekayra - August 11, 2009 - 18:02

Thanks all. It really eased the implementation.

#48

corona ronin - August 28, 2009 - 03:05

Hey,

Wondering: Is there any way to show both location.module locations AND cck locations in the same view?

Thanks,

CR

#49

drew reece - August 28, 2009 - 11:42

I don't think location.module is exposed to views. I haven't seen a module to do this either, but you could skim the Drupal 6 location modules.

The location & mapping group may have more help.

#50

DamienMcKenna - August 28, 2009 - 20:52

This is probably partly related to #391160: CCK/Views: location_instance fix.

#51

nirbhasa - September 6, 2009 - 01:16

Location CCK is updated to include Gmaps views, without need to install Views or Gmap field

http://drupal.org/node/511378

#52

joey santiago - November 13, 2009 - 14:23

cool!
it was quite hard for me to set it up properly, so i add a couple hints:

first of all, go to views, add a new one.

at first, create the relationship and choose the Content: Map field you want to use

Then, create the fields Location: Latitude and Location: Longitude choosing for both the Location relationship you created before.

At this point you can edit the view style under the Basic Settings section, choose GMap, Choosing "Choose lat/long fields" and choose the fields you created.

Then you can use a block to display the map in directly in the node... at least, i think :)

#4 and #8 are very good hints... thanks everyone!

#53

Daves - November 13, 2009 - 17:56

Hi

What about if I want to output the GMAP from a theme template file ? I can't find any examples of doing this when the latitude and logitude are stored as CCK rather than using the straight location module stuff. This code below worked before, but now I would rather work with the CCK version but don't know how to extract the the lat/long from the location CCK fields ?

<?php
if ( ($location['latitude'] != 0) && ($location['longitude'] != 0) && ($teaser != 1) )
{
$homes=array(‘id’ => ‘outfittermap’,
‘zoom’ => 8,
‘width’ => ‘300px’,
‘height’ => ‘200px’,
‘type’ => ‘Map’,
‘latitude’ => $location['latitude'],
‘longitude’=> $location['longitude'],
‘markers’ =>
array( array(
‘markername’ => ‘blue’,
‘latitude’ => $location['latitude'],
‘longitude’ => $location['longitude']
))
);
$outfittermap = theme(‘gmap’, array(#settings’ => $homes));
print $outfittermap;
}
?>

Any pointers appreciated.

Cheers

Dave

P.S. This specific example was cut and pasted from http://www.helpfultalk.com/cms-wikis/mashup-of-gmap-into-your-drupal-web....

#54

nickl - November 26, 2009 - 05:13
Status:active» duplicate

Moving this to the documentation project documentation/faq/help so that we don't loose any vital information collected here.

There are fixes in place for the cck views fields ready for review CCK/Views: location_instance fix

A few dublicate node view gmap - feature requests:
node view gmap: block fix
node view gmap: themeing fix
I still believe this feature will be best enabled with location_cck.

Here is the issue for this now: node view gmap: location cck fix which will make cck handle the node view with map included and enable theme support.

#55

ChrisRut - December 7, 2009 - 00:11

subscribe (for reference)

 
 

Drupal is a registered trademark of Dries Buytaert.