Index: gmap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.module,v
retrieving revision 1.92
diff -u -p -r1.92 gmap.module
--- gmap.module	5 Dec 2008 17:35:51 -0000	1.92
+++ gmap.module	15 Dec 2008 04:34:41 -0000
@@ -1142,21 +1142,11 @@ function gmap_get_key() {
 }
 
 /**
- * Implementation of hook_views_plugins().
+ * Implementation of hook_view_api().
  */
-function gmap_views_plugins() {
+function gmap_views_api() {
   return array(
-    'module' => 'gmap',
-    'style' => array(
-      'gmap' => array(
-        'title' => t('GMap'),
-        'help' => t('Displays rows as a map.'),
-        'handler' => 'gmap_plugin_style_gmap',
-        'theme' => 'gmap_view_gmap',
-        'uses row plugin' => TRUE,
-        'uses options' => TRUE,
-        'type' => 'normal',
-      ),
-    ),
+    'api' => 2.0,
   );
 }
+
Index: gmap.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.views.inc,v
retrieving revision 1.1
diff -u -p -r1.1 gmap.views.inc
--- gmap.views.inc	17 Sep 2008 22:47:10 -0000	1.1
+++ gmap.views.inc	15 Dec 2008 04:34:41 -0000
@@ -9,7 +9,6 @@
 /**
  * Implementation of hook_views_handlers().
  */
-/*
 function gmap_views_handlers() {
   return array(
     'info' => array(
@@ -23,8 +22,25 @@ function gmap_views_handlers() {
   );
 }
 
-*/
-
+/**
+ * Implementation of hook_views_plugins().
+ */
+function gmap_views_plugins() {
+  return array(
+    'module' => 'gmap',
+    'style' => array(
+      'gmap' => array(
+        'title' => t('GMap'),
+        'help' => t('Displays rows as a map.'),
+        'handler' => 'gmap_plugin_style_gmap',
+        'theme' => 'gmap_view_gmap',
+        'uses row plugin' => TRUE,
+        'uses options' => TRUE,
+        'type' => 'normal',
+      ),
+    ),
+  );
+}
 
 function template_preprocess_gmap_view_gmap(&$vars) {
   $vars['map_object'] = $vars['rows'];
Index: gmap_plugin_style_gmap.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap_plugin_style_gmap.inc,v
retrieving revision 1.3
diff -u -p -r1.3 gmap_plugin_style_gmap.inc
--- gmap_plugin_style_gmap.inc	24 Nov 2008 22:47:12 -0000	1.3
+++ gmap_plugin_style_gmap.inc	15 Dec 2008 04:34:41 -0000
@@ -12,20 +12,19 @@
  * @ingroup views_style_plugins
  */
 class gmap_plugin_style_gmap extends views_plugin_style {
+  var $name_lat = '';
+  var $name_lon = '';
+
   /**
    * Set default options
    */
   function option_definition() {
     $options = parent::option_definition();
 
-    $options['macro'] = array(
-      'default' => '[gmap ]',
-    );
-
-    $options['datasource'] = array(
-      'default' => 'location',
-    );
-
+    $options['macro'] = array('default' => '[gmap ]');
+    $options['datasource'] = array('default' => 'location');
+    $options['field_lat'] = array('default' => '');
+    $options['field_lon'] = array('default' => '');
     $options['markers'] = array('default' => 'static');
     $options['markertype'] = array('default' => 'drupal');
 
@@ -34,8 +33,13 @@ class gmap_plugin_style_gmap extends vie
 
   function query() {
     if ($this->options['datasource'] == 'location') {
-      $this->view->query->add_field('location', 'latitude', 'gmap_lat');
-      $this->view->query->add_field('location', 'longitude', 'gmap_lon');
+      $this->name_lat = $this->view->query->add_field('location', 'latitude', 'gmap_lat');
+      $this->name_lon = $this->view->query->add_field('location', 'longitude', 'gmap_lon');
+    }
+    if ($this->options['datasource'] == 'autodetect') {
+      $handlers = $this->display->handler->get_handlers('field');
+      $this->name_lat = $handlers[$this->options['field_lat']]->field_alias;
+      $this->name_lon = $handlers[$this->options['field_lon']]->field_alias;
     }
 
     if ($this->options['markers'] == 'nodetype') {
@@ -51,9 +55,14 @@ class gmap_plugin_style_gmap extends vie
       vpr('gmap_plugin_style_gmap: Missing row plugin');
       return;
     }
+    if (empty($this->name_lat) || empty($this->name_lon)) {
+      vpr('gmap_plugin_style_gmap: Missing lat/lon field');
+      return;
+    }
 
     $markername = isset($this->options['markertype']) ? $this->options['markertype'] : 'drupal';
 
+    // FIXME: What's the purpose of this?
     $markertypes = variable_get('gmap_node_markers', array());
     if ($this->options['markers'] == 'nodetype') {
       $markertypes = variable_get('gmap_node_markers', array());
@@ -69,8 +78,8 @@ class gmap_plugin_style_gmap extends vie
       $markers = array();
       $offsets = array();
         foreach ($records as $label => $row) {
-        $lat = (float)$row->gmap_lat;
-        $lon = (float)$row->gmap_lon;
+        $lat = (float)$row->{$this->name_lat};
+        $lon = (float)$row->{$this->name_lon};
         if (!empty($lat) && !empty($lon)) {
           if ($this->options['markers'] == 'nodetype') {
             if (isset($markertypes[$row->gmap_node_type])) {
@@ -95,6 +104,7 @@ class gmap_plugin_style_gmap extends vie
           $offsets[$markername]++;
         }
       }
+
       if (!empty($markers)) { // Don't draw empty maps.
         $map = gmap_parse_macro($this->options['macro']);
         $map['markers'] = $markers;
@@ -122,11 +132,38 @@ class gmap_plugin_style_gmap extends vie
       '#title' => t('Data Source'),
       '#options' => array(
         'location' => t('Location.module'),
-        'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'),
+        'autodetect' => t('Fields named "latitude" and "longitude"'),
       //'geocode' => t('Just-in-time geocoding on field named "address"'),
       ),
       '#default_value' => $this->options['datasource'],
-      '#multiple' => FALSE,
+    );
+
+    // Create an array of allowed columns from the data we know:
+    $field_names = array();
+    $handlers = $this->display->handler->get_handlers('field');
+    foreach ($handlers as $field => $handler) {
+      if ($label = $handler->label()) {
+        $field_names[$field] = (string) $label;
+      }
+      else {
+        $field_names[$field] = (string) $handler->ui_name();
+      }
+    }
+    $form['field_lat'] = array(
+      '#type' => 'select',
+      '#title' => t('Latitude field'),
+      '#options' => $field_names,
+      '#default_value' => $this->options['field_lat'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:style_options[datasource]' => array('autodetect')),
+    );
+    $form['field_lon'] = array(
+      '#type' => 'select',
+      '#title' => t('Longitude field'),
+      '#options' => $field_names,
+      '#default_value' => $this->options['field_lon'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:style_options[datasource]' => array('autodetect')),
     );
 
     $form['markers'] = array(
@@ -152,4 +189,12 @@ class gmap_plugin_style_gmap extends vie
       '#default_value' => $this->options['markertype'],
     );
   }
+
+  function uses_fields() {
+    // The 'audodetech' option requires that we have lat and lon fields.
+    if ($this->options['datasource'] == 'autodetect') {
+      return TRUE;
+    }
+    return parent::uses_fields();
+  }
 }
