Views + GMaps: a perfect match

zacker's picture
· ·

Story: On Saturday night Drummy, Tony, and I went to Super Happy Dev House IX. I was a bit drunk. I bet Neil and Tony that I the "business guy" would beat them the "hackers" at hacking. My goal for the night was to integrate the gmaps module with views to allow users to create maps of any view.

I won handily:
http://zacker.org/mapdev/?q=mapview

Here is the theme code required to do this (add to template.php):

<?php
function phptemplate_views_view_list($view, $nodes) {
 
$thismap = gmap_parse_macro('[gmap|id=viewmap|center=37,-100|zoom=3|width=100%|height=400px]');
  foreach (
$nodes as $node) {
   
$node_data = node_load(array("nid"=>$node->nid));
   
$location = $node_data->location;
   
$newmarker['label'] = '';
    foreach (
$view->field as $field) {
     
$newmarker['label'] .= "<p>" . _views_handle_field($fields, $field, $node) . "</p>";
    }
   
$newmarker['point']= $location['lat'] . ',' . $location['lon'];
   
$newmarker['markername']='drupal_view';
   
$thismap['markers'][]= $newmarker;
  }
 
$output .= gmap_draw_map($thismap);
  return
$output;
}
?>

Login to post comments

Looks like you’re running

merlinofchaos's picture
merlinofchaos - Mon, 2006-05-01 23:07

Looks like you're running into Views & node_access not getting along very well. :/


:(

zacker's picture
zacker - Mon, 2006-05-01 23:29

Yeah..... Try reloading, should work now.


Be careful...

robertDouglass's picture
robertDouglass - Tue, 2006-05-02 04:00

there's a known shortage of Drupal developers. If you let on that you understand this stuff we're going to turn you into a code monkey! =)


demo is missing

christefano's picture
christefano - Tue, 2007-07-17 01:05

Zack, can you post a link to a working demo? All I found on your site was http://zacker.org/gmaps-views-a-happy-hack and a link to http://drupal.org/node/61335. No demo.


Don't worry...

NikLP's picture
NikLP - Tue, 2007-07-17 12:05

I don't think you really need the demo any more. You can achieve what Zack has done here by just using Views and GMap "as is" now, since GMap now has Views support. Hence, you can add a View which displays a map of nodes as per the rest of the Views settings (filters, etc).


verify?

YesCT's picture
YesCT - Sat, 2008-11-22 05:08

How can I verify that my gmap version has views support? I dont see gmap as an option for the view type, when I try to add a new view...

6.x-1.0-rc2, 6.x-2.1

Thanks!

Cathy Theys
http://YesTrainingAndEducation.com


You are right

christefano's picture
christefano - Tue, 2007-07-17 13:57

I was hoping for a demo so I could show it to someone. So much for trying to get away with being lazy. :)


a demo for what it's worth

bcswebstudio's picture
bcswebstudio - Tue, 2007-07-17 14:56

For what it's worth, here's my gmap based on a view with some custom theming on the nodes to make tabs in infoWindow:
http://bchc.co.brazos.tx.us/histmarkers-map
If the site doesn't come up for you, pls pm me with relevant info-- having some troubles with dns.


cool!

MikeyLikesIt's picture
MikeyLikesIt - Tue, 2007-07-17 22:51

I dig thickbox integration and the option to view the info in both list and map format. Do you enter the lat/long info manually or is it calculated from addresses?


Cool :)

NikLP's picture
NikLP - Wed, 2007-07-18 09:29

Yup, Nik likes it too...! :)

Any chance you could share some of the theming info? I urgently need to theme some map markers and popups this week, and I don't as yet have any information on it... ( pretty please? :p )

I'm using the latest gmap/views/cck of course (dev/1.6/1.5)

PS no dns issues for me


tricky stuff..

bcswebstudio's picture
bcswebstudio - Wed, 2007-07-18 13:10

Thanks guys. Before I or someone can get around to make a handbook, the basics might be gleaned from my infoWindow tabs request here:
http://drupal.org/node/153018

Regarding thickbox: yeah that was a tricky one.. I couldn't get the thing to initialize consistently (an init per node was crazy and only worked in firefox not in IE), so I invite you inspect the output* for how I devised a workaround. If you can think of something better, I am all ears! "I tried everything."

(* it's just more fun that way :D)

Wow, at 8am Central US, d.o is smokin' fast!


GMap module vs. "GMaps" module

christefano's picture
christefano - Fri, 2008-11-21 08:34

If anyone is wondering after seeing the title, this is about GMap and not GMaps.