I configured a view to show the results in a map setting the option "choose latitude and longitude fields" and selecting a custom float fields to be used as lat/lon. Also i tried to use a geofield to be the data source lat/lon but is not directly supported although in theory you can add two times the field to the views field and select the geofield formatter to lat/lon separated one per instance of the field.

The problem no matter where is the source of the lat/lon when you choose the lat/lon fields, the view doesn't paint the gmap markers. There are other bug reports that suggest a patch http://drupal.org/node/1061444 but doesn't work for me and i discovered that this is other issue.

I'm using the 7.x-1.x-dev version of Gmap and is important to mention that i'm using the 7.x-3.x-dev version of Views. After many hours of debug and looking other reported issues discovered that the problem is in the Gmap Style plugin "gmap/gmap_plugin_style_gmap.inc". Only investigated with the Gmap Style not the Gmap Extended. Not sure if is problem of Views or Gmaps the conflictive lines (start line 94) are:

    // Determine fieldname for latitude and longitude fields.
    if ($this->options['datasource'] == 'fields') {
      $lat_field_obj = $this->view->display_handler->get_handler('field', $this->options['latfield']);
      $lon_field_obj = $this->view->display_handler->get_handler('field', $this->options['lonfield']);
      $lat_field = $lat_field_obj->field_alias;
      $lon_field = $lon_field_obj->field_alias;
    }

The field_alias returned by the get_handler doesn't return the correct name of the field. In the configuration the names of the fields are set without the 'field_' prefix which have all the custom fields when get the field_alias property of the field handler it doesn't return the correct name. As consequence when the render() method try to build de markup the next vars are empty (start line 152):

      foreach ($records as $row_index => $row) {
        $this->view->row_index = $row_index;
        $lat = (float)$row->{$lat_field};
        $lon = (float)$row->{$lon_field};

If the $lat_field is malformed the $row key will be empty, in my case i have a custom float fields named 'field_lat' and 'field_lon' and they are named in the $row object as 'field_field_lon' and 'field_field_lan'. Of course the value is not correctly obtained by the above code and as a result the markers are not properly generated.

I'm working in a patch, but need to test with previous version of Views to discard a bug from that module. If someone else is experimenting this problem we can work together to fix Gmaps, i discover other bugs and noted that the las release was on April 2011 i supose the developers are busy in other things and we can help to stabilize Gmaps.

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

citlacom’s picture

Status: Active » Needs review
FileSize
3.93 KB

As i promised, i was working in the solution of this issue and in the way i found that support a new lat/lon source was very easy, then added support to the geofield type fields. http://drupal.org/project/geofield

I tested the patch using lat/lon source from location.module, geofield.module or custom field as float field separated fields for lat and lon. With this changes the markers work as expected. If someone have the same problems and test it, please give feedback to improve the patch.

upupax’s picture

I got an error applying the patch.

Hunk #1 FAILED at 88.

upupax’s picture

I manually applied the patch, but still have no possibility to choose gmap as view style for geofield.

citlacom’s picture

Hi Upupax,

To create a view with Gmap as view style you should follow the next steps:

- create a view with field output as fields and filter the nodes by the content types that have a field of type geofield.
- in the style type there are two options "Gmap" and "Gmap extended" this patch apply only to Gmap style. When you select that style in the configuration you should set the source to "geofield.module" and configure the source field to one of the added fields to your view. Is required to add at least the title and geofield for the fields of your view.
- then if you go to the path of your View you can see the map. I recommend you to review all the Gmap configurations in the path /admin/config/services/gmap

This is a View style and not a field formatter, to make it work you must create a View for the content that you want to geolocate in a map.

citlacom’s picture

Something was wrong generating the first patch, i add it again, now it works applied with command:
patch < style_gmap_customfields_geofields_support.patch at module gmap path.

upupax’s picture

No way. The map is not displayed at all.
Which versions of Gmap/Views are supposed to work with?

upupax’s picture

Ok, upgrading to views -dev solved the issue!
Thank you!

seddonym’s picture

Yes worked for me too, just using text fields for long/lat (no geocode module).

It's been nearly a year since this was opened, any plans to include this patch in the next release?

podarok’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Fixed

#5 rerolled

thanks!!
commited / pushed to 7.x-2.x

podarok’s picture

FileSize
3.91 KB

the patch against 7.x-1.x

commited / pushed

thanks!

podarok’s picture

Status: Fixed » Needs work
marco.abiuso.questar’s picture

Hi,
apparently your patch is not working as expected.

I did some debugging and it seems you need to use field_alias anyway.

In your patch you remove

-      $lat_field = $lat_fied_obj->field_alias;
-      $lon_field = $lon_field_obj->field_alias;

Can you see there is a misspelling in "$lat_fied_obj"? Is this your mistyping or the original source had this error?!?! Maybe that was the original problem...

I'm using datasource == fields on Views 3.5 and the field names are prefixed in the query with the table name (=field_alias), but this patch uses the field_name instead of field_alias.

So I reverted gmap_plugin_style_gmap.inc from

      $lat_field = $this->options['latfield'];
      $lon_field = $this->options['lonfield'];

to

     $lat_field = $lat_fied_obj->field_alias;
     $lon_field = $lon_field_obj->field_alias;

and from

				$lat = (float)$custom_field_lat['value'];
				$lon = (float)$custom_field_lon['value'];

to

				$lat = (float)$row->{$lat_field};
				$lon = (float)$row->{$lon_field};				  

and now everything works!
If you need a patch file, just let me know

podarok’s picture

yes, please, provide a patch for review

podarok’s picture

Status: Needs work » Closed (fixed)
FileSize
1.34 KB

fixed #12

commited pushed to 7.x-2.x and 7.x-1.x

alex.neblett’s picture

Status: Closed (fixed) » Needs work

@podarok

Your patch introduced a typo:

$lat_field = $lat_fied_obj->field_alias;

should be

$lat_field = $lat_field_obj->field_alias;

Cheers,

Alex

podarok’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
664 bytes

fix for 7.x-1.x release

podarok’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

commited pushed to 7.x-1.x

the same patch for 7.x-2.x

podarok’s picture

Status: Needs review » Fixed
johnv’s picture

Priority: Critical » Normal
Status: Fixed » Needs review
FileSize
3.03 KB

I thought it is better to reopen this, then to open a new issue.
Please see attached patch.
It contains faster, shorter code and aligns better the 3 options location/geofield/fields.

Please test.

podarok’s picture

Status: Needs review » Needs work
Issue tags: -views, -custom fields, -markers, -bug gmap +Needs tests, +Needs manual testing

would be nice see screenshots before-after for manual testing
#19 looks good for me
+ tag for Needs tests

johnv’s picture

Status: Needs work » Needs review
FileSize
155.1 KB
158.3 KB

Hi, I tested #19 with today's dev version, and i was surprised that the lat/lon fields did not show up at all anymore.
Thi patch fixes this (again).
Please find before and after screenshots of the test views.
You can see the 'Fields' display is empty the first time.

I'm aware we are 'toggleing', regarding this feature.

podarok’s picture

#21 hmm

podarok’s picture

podarok’s picture

Category: bug » task
Status: Needs review » Needs work

#19 commited pushed to 7.x-2.x
this should be checked for gmapextended too

podarok’s picture

Component: Code » gmap_plugin_style_gmapextended.inc

changed component as ToDo

podarok’s picture

stella’s picture

This patch assumes that you are working with the Fields API for the "choose latitude and longitude fields" option. It completely breaks my view which is displaying a map of contacts from CiviCRM. Those field names are "geo_code_1" and "geo_code_2". The aliases are "civicrm_address_geo_code_2" and "civicrm_address2_geo_code_2". As you can see prepending "field_" to the field names, doesn't work. In addition, looking at $row->{$lat_field}[0]['raw']['value'] also doesn't work as the data is stored directly in $row->civicrm_address_geo_code_1, etc.

johnv’s picture

Component: gmap_plugin_style_gmapextended.inc » gmap_plugin_style_gmap.inc

#27 is about the 'normal' plugin. After correcting that, we can 'backport' to GMAP Extended plugin.

stella’s picture

actually just tried with the gmap extended plugin and that one works fine.

jomarocas’s picture

Hi i tested the latest version of gmap 7.x-2-11.x-dev and for me no working i update the issue to active, the patch #16 was in dev, but for me no working, i think my problems that no show is for this issue, i use lat and long fields and no working with various markers, for one marker working, any ideas for this, thanks

jomarocas’s picture

Status: Needs work » Active
jomarocas’s picture

Status: Active » Closed (works as designed)

For me work at expect, i choose lat and lon fields, try updata to latest version dev of this module