Last updated August 13, 2009. Created by Zack Rosen on May 2, 2006.
Edited by m1mic, sepeck. Log in to edit this page.
description
This snippet will allow you to show google maps on 'views' of drupal content.
Step 1 of 2
Install the views module, location module, and gmaps module.
Step 2 of 2
Copy this code into your template.php file:
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;
}Now instead of displaying views content in a 'list' your content will appear in a Google map.
Note: The gmaps module version DRUPAL-5.x and above has views module integration built in
Comments
Great Help!
Thanks to this blog I finally managed to find the information matching my criteria and for this I would like to thank the author for sharing this blog with us. Looking forward for more. granite countertops fairfax