Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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