1. Create a content type/entity type and add a location field to it (or to an existing node/entity)
2. Create a Node/Entity from new/updated type, filling in a valid address in the location field
3. Create a View aggregating your new/updated content/entity type
4. Choose Gmap as the Plugin
5. Choose the Location Field as one of the Views Fields
6. In the Gmap Plugin settings, Select 'Choose lat/lon fields' and then select your Location field as your lat and lon fields.
7. Opt to use the Location field as your marker
8. Present your Location Field as the Bubble text
9. View your View
10. Cry out in utter frustration at the inability to make it work.

I found it extremely frustrating that I couldn't tell the GMap plugin in views that my lat/lon info or my bubble/marker info came from the Location field. Isn't D7 all about fields? Personally, I love fields! Which is why I had to remedy this.

Here's the patch to fix this. I tried to retain as much of the current functionality as possible as a safe fallback. And I only wrote code that affected the 'fields' area when rendering the Gmap. Now it will look for lat/long, marker info and the rendered out put of the location field (for the bubble) when the info is applicable.

I did change how the field information was processed. I didn't think it was safe to use $row->{$field_alias} in instances when you need field data. There's a field handler object with a field_info property that is better at handling field information than an alias in a db field (remember, whether it's aliased or not, it's selected in the query). $field_handler_obj->field_info['field_name'] is more safe. Then you just use $row->{'field_'.$field_handler_obj->field_info['field_name']} instead.

Anyway, I haven't done too much testing with this. The patch attached worked for me and I hope it helps others as well. Please, someone, test test test. Can't wait for v3 to get in production. Anyone thinking about a way to tap into the DrivingDirections functionality?? I guess I could figure out a way using jQuery and the mapid.

Thanks!

Comments

curiosity26’s picture

StatusFileSize
new10.01 KB

Blah! Didn't attach the patch.

Status: Needs review » Needs work

The last submitted patch, gmap-location_field_cck-0.patch, failed testing.

johnv’s picture

v2.5 is an erroneous, outdated, version. Can you provide a patch against 7.x-2.x version?
It is hard to see which code is changed/reverted deliberately.
see #1955230: Tag for 7.x-2.5 is NOT correct. It publishes an OLD version!

podarok’s picture

Version: 7.x-2.5 » 7.x-2.x-dev
Status: Needs work » Needs review

bumping version

podarok’s picture

#1: gmap-location_field_cck-0.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, gmap-location_field_cck-0.patch, failed testing.

podarok’s picture

#1 needs reroll
+

+++ b/gmap_plugin_style_gmap.incundefined
@@ -50,10 +50,10 @@ class gmap_plugin_style_gmap extends views_plugin_style {
-
+    ¶
     $options['bubbletextenabled'] = array('default' => 0);
     $options['bubbletextfield'] = array('default' => '');
-
+    ¶
+++ b/gmap_plugin_style_gmap.incundefined
@@ -102,27 +102,38 @@ class gmap_plugin_style_gmap extends views_plugin_style {
     }
-
+    ¶
     // Determine rmt field.
+++ b/gmap_plugin_style_gmap.incundefined
@@ -133,15 +144,14 @@ class gmap_plugin_style_gmap extends views_plugin_style {
+    ¶
+    // Let's make sure the individual fields are rendered ¶
     $this->render_fields($this->view->result);
-
+    ¶
     // Render each group separately and concatenate.  Plugins may override this
+++ b/gmap_plugin_style_gmap.incundefined
@@ -176,13 +186,31 @@ class gmap_plugin_style_gmap extends views_plugin_style {
+          $custom_field_lon = isset($row->{$custom_field_lonname}[0]['raw']) ? $row->{$custom_field_lonname}[0]['raw'] : NULL;
+          ¶
+          if (is_array($custom_field_lat) && !empty($custom_field_lat['latitude']))
+            $lat = (float)$custom_field_lat['latitude'];
+          ¶
+          if (is_array($custom_field_lon) && !empty($custom_field_lat['longitude']))
+            $lon = (float)$custom_field_lat['longitude'];
+          ¶
+          if ($custom_field_lat && !$lat)
+           $lat = (float)$row->{$lat_field};
+          ¶
+          if ($custom_field_lon && !$lon)
+++ b/gmap_plugin_style_gmap.incundefined
@@ -231,14 +259,26 @@ class gmap_plugin_style_gmap extends views_plugin_style {
-
+          ¶
           $bubbletext = NULL;
+++ b/gmap_plugin_style_gmap.incundefined
@@ -231,14 +259,26 @@ class gmap_plugin_style_gmap extends views_plugin_style {
+              $bubbletext_field_alias = $bubbletext_field_obj->field_alias;
+              ¶
+            if (!empty($bubbletext_field_alias) && !empty($row->{'field_'.$bubbletext_field_alias})) {
+++ b/gmap_plugin_style_gmap.incundefined
@@ -524,7 +562,7 @@ class gmap_plugin_style_gmap extends views_plugin_style {
-
+    ¶

lot of whitespace errors
http://drupal.org/coding-standards#indenting

curiosity26’s picture

Version: 7.x-2.x-dev » 7.x-2.7
Component: Code » gmap_plugin_style_gmap.inc
Status: Needs work » Needs review
Issue tags: +location cck, +location cck views
StatusFileSize
new1.87 KB

Ok I noticed many updates in v2.7, but still leaving out the catch for the actual Location CCK Field. I don't see the dev branch in git, so I just will have to work with the latest release. Here's the newest patch. Can't seem to do an easy way with gmap extended. But! You can at least pull out the lat and long values individually in views if you had to use gmap extended.

curiosity26’s picture

SCORE!!

johnv’s picture

Status: Needs review » Needs work

I'm glad you did the trick, curiosity26.
Some remarks:
if (is_array($custom_field_lat) && !empty($custom_field_lat['latitude'])) {
- Isn't this always (TRUE && TRUE) for Field API fields? At least, if $custom_field_lat['latitude'] exists? This might be enough:
if (isset($custom_field_lat['latitude'])) {
- A bit of documentation wouldn't hurt, for later reference.
- you still have problems with indentation, trailing spaces and tab's. Try the Coder module. After installation, you can activate it from admin/modules page.
- IMO below (untested) version would do the trick, too.

        elseif ($this->options['datasource'] == 'fields') {
          // A default field API field.
          $lat = isset($row->{$lat_field}[0]['raw']['value']) ? (float) $row->{$lat_field}[0]['raw']['value'] : NULL;
          $lon = isset($row->{$lon_field}[0]['raw']['value']) ? (float) $row->{$lon_field}[0]['raw']['value'] : NULL;
          // A location CCK field.
          if (!$lat || !$lon) {
            $lat = isset($row->{$lat_field}[0]['raw']['latitude']) ? $row->{$lat_field}[0]['raw']['latitude'] : NULL;
            $lon = isset($row->{$lon_field}[0]['raw']['longitude']) ? $row->{$lon_field}[0]['raw']['longitude'] : NULL;
          }
          // A ... field.
          if (!$lat || !$lon) {
            $lat = (float)$row->{$lat_field};
            $lon = (float)$row->{$lon_field};
          }
        }
curiosity26’s picture

I'm sorry. I know I have issues. I switch between Komodo Edit and vim (depending on where I'm working at the time). I agree that is_array might not bet the best solution. Perhaps just using the !empty($custom_field_lat['longitude']) is enough. I can add some additional documentation.

All in all I'm just getting used to this community thang. I've been a developer for about 10 years and Drupal is the first communal thing I've worked on. So I appreciate the helpful references.

Please let me know if you would like me to clean up and resubmit.

Thanks!

curiosity26’s picture

StatusFileSize
new1.36 KB

Ok I did some major cleanup. I realized a lot of the code I had was because of my attempt to port back in v 2.5. Many of the prerequisite fixes are in place in v 2.7 so not all of that code was necessary. I included comments and matched the indentation as defined by the document standard. I hope this is a more clean and refined patch than the previous.

Thanks!

podarok’s picture

Version: 7.x-2.7 » 7.x-2.x-dev
Status: Needs work » Needs review

2 @curiosity26
If You uploading a patch , please tag it with needs review status https://drupal.org/node/156119 and latest dev version for testbot

podarok’s picture

Status: Needs review » Needs work
+++ b/gmap_plugin_style_gmap.incundefined
@@ -199,6 +199,12 @@ class gmap_plugin_style_gmap extends views_plugin_style {
+	  ¶
+          // Field is Location CCK
+ 	  if (!$lat || !$lon) {

whitespace errors
http://drupal.org/coding-standards#indenting

jerenus’s picture

Status: Needs work » Needs review
StatusFileSize
new1.75 KB

Rerolled it.

podarok’s picture

Component: gmap_plugin_style_gmap.inc » gmap_plugin_style_gmapextended.inc
Priority: Normal » Critical
Status: Needs review » Needs work
Issue tags: -location cck, -location cck views

#15 commited pushed to 7.x-2.x
this one needs rework to extended views plugin style so moving to critical!
nice work
thanks!

pearl.liang’s picture

Just want to share my experience. I had the same problem with 7.x-2.x updated in Oct 2013.
Later my problem is solved by unchecking "Use a Google Map to set latitude and longitude" under "admin/config/content/location". It automatic enable geocoding.