Last updated 13 August 2009. Created on 2 May 2006.
Edited by m1mic, sepeck, Zack Rosen. 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

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.