Community Documentation

Google map view

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

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here