On my site it is commong for multiple markers to be on a single lat/lon within a GMap.

Is there anything you can do to make these markers distinct, within the module itself?

If not, can you lead me in the right direction?

Cheers!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kvvnn’s picture

Update : I have a funds for this request.

Elaboration : Create some sort of interface within the GMap to display multiple markers at a single location, and allow users to find and click them individually.

sagannotcarl’s picture

I believe if you use Jef Poskanzer's Clusterer and set Popup mode to Original (in /admin/settings/gmap), when you click on a cluster it shows all the points within that cluster in the popup. May not be ideal but it will get you part way there.

super_romeo’s picture

subscribe

dieter’s picture

subscribing

amedee-1’s picture

+1 subscribing

I have written about this in the Location & Mapping group, but perhaps it makes more sense here.
http://groups.drupal.org/node/23164#comment-87275

I have the same issue, but with nodes, not users.
I have a test case with 2 modules with exactly the same location:
http://foutparkeerders.be/kaart
Zoom into Gent, Voskenslaan - a street in the SW of the city. There are 3 nodes in that street: one near Schoonmeersstraat and two with identical location near Tuinwijklaan. These two nodes with identical location are:
http://foutparkeerders.be/node/5
http://foutparkeerders.be/node/50
Only node/5 is shown in the popup when I use no marker manager.

I have tested the following marker managers:

  • Google's GMarkerManager
    No clustering
  • Gmaps Utility Library MarkerManager
    No clustering
  • Jef Poskanzer's Clusterer
    Shows list of nodes in a popup
    My settings:
    • Activate on: 2 or more markers
    • Cluster on: 2 or more markers
    • Lines per box: 10 at most lines

    Results:

    • with popup mode Zoom to Cluster: cluster until the last detail (GOOD), no popup (BAD)
    • with popup mode Original: cluster until the last detail (GOOD), cluster popup only shows location icons, not the node fields that were defined in the View (BAD), no links to the nodes (the links were defined inside the View) (BAD)
  • Martin Pearman's ClusterMarker
    • Shows a cluster until the last but one zoom (BAD)
    • On the final zoom, only the first node is shown (BAD)
    • Customizable cluster message with %count variable (GOOD)

 

I would like to see a cluster that works mostly like Jef Poskanzer's Clusterer, with the following features:

  • cluster until the last zoom
  • popup when marker is clicked
  • marker shows list (UL) of nodes with the fields as defined in the View
  • It is up to the user to define a field in the View that provides a link to the node
  • Customizable cluster message with %count variable (as in Martin Pearman's ClusterMarker)

The qestion of kvnBushi was extremely short, but I think that I understand the problem. I need the same for my site. I'm confident that if I can get it to work exactly as described above, then kvnBushi will also have his solution. I tried to give as much detail as possible. Hopefully this will help a developer that wants to work on it.

amedee-1’s picture

Possibly related issues:

I found other possibly related issues, but they were more than a year old.

amedee-1’s picture

UPDATE: mostly solved, seee comment http://drupal.org/node/329281#comment-1920180
kvnBushi can you confirm that this is also a solution for you?

kvvnn’s picture

Status: Active » Closed (fixed)

Yes, that helps me.

Thanks.

rares’s picture

Status: Closed (fixed) » Active

I understand that the solution on http://drupal.org/node/329281#comment-1920180 fixes some problems, but in the end that comment says that

The only remaining problem is that there is no clustering with the closest zoom; you get the default popup with only one node.

The point of this thread was exactly to solve the problem of needing "multiple markers to be on a single lat/lon", in the clusterer zoom to cluster mode.
The only solution I've found to that is in a draft version here: http://drupal.org/node/155104#comment-1726644

kvvnn’s picture

I have a custom built solution that using theme overrides in the view (.tpl.php) to show a list of nodes (views fields) when you click on a location within a GMap.

Its pretty specific to my site, and there is a lack of documentation, and I can't really provide support (I outsourced the functionality), but I will post here as soon as I get some time to organize some instructions.

I will post a link w/ an example and instructions, as well as the them override in a few days.

Sorry for the teaser, I just want to hold myself to it but there is no way I can handle it tonight.

Cheers!

kvvnn’s picture

Here is our testing server for the implementation : http://test2.venuslabs.co.in/gmapTabs

kvvnn’s picture

I'm still working on this guys. I'll probably open up a drupal install on my server as an active example, like the above. Its somewhat complicated because we used template overrides.

Soon,

mErilainen’s picture

I'm really interested to use your implementation, as I have two different maps of users' profiles which I want to show. Other one is a map of user's home location and another one is where the user is currently studying. I don't have many overlapping locations in the home location map, but many students live in the same building, so they share the same location also.

kvvnn’s picture

For now, I would appreciate if you emailed me using the contact form, and once we figure out how to make it work for you we'll post some general instructions on here.

ChrisRut’s picture

:subscribe:

kvvnn’s picture

If anyone wants the raw files just send me a message via contact form, and I can offer specific help. Hopefully I'll get some time to put up a proper instructional w/ attachments.

kvvnn’s picture

Disclaimer
Alright, here goes. This can be an ugly process if we don't do it together. I expect you all to return the favor by posting issues you have, with resolves if they are found, and in general just being communicative.

Prerequisites
You need to have a working View that has a table list of latitude/longitude values plus any information pertaining to that location and its respective node, with a Gmap that displays the map of the nodes. See http://drupal.org/node/386848#comment-1368296 if you have not completely mastered Views for Location CCK + Gmap.
--------------------
Overview
Goal: to create a View that contains a list of fields pertaining to a location, with a Gmap that is designed around displaying multiple node fields for the exact same location. By location, I technically mean a specific latitude and longitude value.

The only limitation to the setup at http://drupal.org/node/386848#comment-1368296, is that multiple nodes cannot be displayed for a single location. To do this, we need to implement a Views Override. I will not provide instructions on how to do that, so go look it up if you need to, but will be providing all of the files that will make it work.

Logistics
The way we do this is to create two separate views for one Gmap + List. One view is the view that users see, and another is the view that our Gmap pulls data from. The reason we don't use a single view is due to paging limitations. For example, if we use the same view and the Gmap is pulling data from it, then it can only pull data from whatever page we are on. For my implementation I wanted all data visible on the Gmap no matter what page of the view we were on.

Begin by creating your view as laid out in http://drupal.org/node/386848#comment-1368296. Create a page that displays the list of data and an attachment that is the Gmap. Then clone it.

Static Files
gmap_multiMarkers.js and gmap_multiMarkers-tabs.js are files that should not need any customization. They are tied to our view override on line 116 and 117. You can see that their default locations are "/sites/default/files"

Custom File
gmap_multiMarkers-View-Override.php is our View Override. You will need to customize it heavily in order for it to display your fields, and not the ones I set it up for. Here is a legend by line number :

21 : MAX_FIELD_TEXT is a variable that determines the maximum amount of characters my main field should have. I am applying it on line 51 to one of my fields

22 : MAX_NODES_PER_TAB is a variable that determines the maximum amount of nodes to display per tab. Keep in mind that whatever fields you are using will be displayed per node. For example, if you are using "Node:Title" and "Node:Body" fields and make MAX_NODES_PER_TAB 5, then each tab will have the Title and Body for 5 nodes listed.

35 : $view_name is a variable that references the name of our cloned view

36 : $display is the display of the list we are shooting into our gmap. It needs to be a list from our cloned view that includes latitude and longitude of our location for that node.

46-57 : Here are the fields in our cloned view list display. It was helpful for me to install Views Customfield and follow http://drupal.org/node/467190#comment-2068324 to see how to reference the field names. All of this should be blanked out and rewritten according to your requirements. As you can see I have some popups functionality in there as well.

70 : GMaps API Key

113,114 : Popups Stuff

116,117 : Our required javascript files

118 : This is where we pring out the Gmap. You would put whatever styling values you want here

122-139 : This is where we insert our fields in the Gmap. You'll see on line 134 we are guarding against special characters that will break the Gmap.

145-161 : This is where we insert our fields for a Gmap popup that does not have enough nodes for two tabs.

170 : This is where we print our list. If you guys only want to print a Gmap, you can delete this entire table

Whew. Ask away.

kvvnn’s picture

ChrisRut’s picture

Thanks for the great post Kevin,
Where did you get the files for lines 114-117 in the views override?

  echo '<script type="text/javascript" src="/modules/popups/popups.js"></script>';

  echo '<script type="text/javascript" src="/sites/default/files/tabbed.js"></script>';
  echo '<script type="text/javascript" src="/sites/default/files/advice_gmap.js"></script>';

Am I to assume from the files you posted that:
gmap_multiMarkers-tabs_js.txt = /sites/default/files/tabbed.js
gmap_multiMarkers_js.txt = /sites/default/files/advice_gmap.js

If so where is the /modules/popups/popups.js file?
Is that the popups API module? If so you should probably update your post and add popups API module to the Prerequisites.
Thanks again for posting the instructions+code

kvvnn’s picture

Chris, you are spot on w/ your assumptions. Popups is not a prerequisite, but I used it and it works pretty nicely for the node links on the Gmap tabs window.

mErilainen’s picture

I tried to follow your instructions, but all I get is a blank page instead of map.

This is what I did:

My view is called map_user_living_in which I cloned to map_user_living_in_data, so $view_name = 'map_user_living_in_data';
Then I renamed the gmap_multiMarkers-View-Override_php.txt to gmap-view-gmap--map-user-living-in.tpl.php and did all the modifications to those parts required. Because we are doing the views override for the original view, not the cloned one right?

I used the Views Customfield module to find out the field names of the $views_result variable, but I'm not sure how can I find the right field names for the $result[] array. I tried for example $result['name'] = $view_result->users_name; to get the user's full name, instead of separate first name and last name.

FreddieK’s picture

I whipped up some quick n' dirty code to get around this issue for my views. It doesn't show a cluster marker, but when opening up a marker that is on the same spot as others it will display all of them in the popup window. Should probably be worked in as a configurable option since you might not want this behavior all the time.

function template_preprocess_gmap_view_gmap(&$vars) {
  $vars['map_object'] = $vars['rows'];
  // Rows is actually our map object.
  unset($vars['rows']);

/**
 * Fixes the problem of multiple markers appearing on the same spot.
 */
 
  // Loop through the markers one by one...
  foreach($vars['map_object']['markers'] as $key => $place){
    
    // Check them against all the markers...
    for($i=0 ; $i < sizeof($vars['map_object']['markers']) ; $i++){

      // That is not the current marker...
      if($i != $key){      
          
        // If the coordinates are identical then...
        if(($place['latitude'] == $vars['map_object']['markers'][$i]['latitude']) && ($place['longitude'] == $vars['map_object']['markers'][$i]['longitude'])){
        
          // Copy the text from the identical marker and add it to the current markers text.
          $vars['map_object']['markers'][$key]['text'] .= '<br/>' . $vars['map_object']['markers'][$i]['text'];
        }
      }
    }
  }
  
/**
 * End of added code
 */

  // Theme the map.
  $vars['map'] = theme('gmap', array('#settings' => $vars['map_object']));
}
serhiyvk’s picture

Hi, can you please tell, where would I put this code in order to use it in my views?

EDIT: I see now, this code is to be added in file sites/all/modules/gmap/gmap.views.inc
Just that now I have one issue: in popup for the marker, where there are two same locations, the link to node, which belongs to this marker appears twice.

petrios’s picture

Hi,
solution #22 is usable for me, BUT I have same trouble after adding in gmap.views.inc as serhiyvk - marker appears twice. Thanks you for any advice.

FreddieK’s picture

#23, #24
For me the usecase is that the links are to different nodes, even though they share the same adress. At that point the whole HTML block is generated in ['text'], so you should do some preg_replace() in php to erase links before adding the marker.

Here, that is:

          // Copy the text from the identical marker and add it to the current markers text.
          $vars['map_object']['markers'][$key]['text'] .= '<br/>' . $vars['map_object']['markers'][$i]['text'];

Also, rather than putting the text in gmap.views.inc you should put it in template.php in your theme.

petrios’s picture

Freddie, thx you for your answer, but I didn´t understand what should I do. Honestly, I have only little experience with PHP functions and I don´t know how use preg_replace() in this case and put in template.php. Could you give detailed description?
Thx a lot

Chadwick Wood’s picture

FreddieK, unfortunately the built-in definition of template_preprocess_gmap_view_gmap() calls theme('gmap'), which inserts the javascript for your map markers before yourtheme_preprocess_gmap_view_gmap() will get called. At least, that's what I'm seeing on my site. My solution to that (unfortunately a hack) is to go into gmap.views.inc in the module and comment out line 35 or so:

//  $vars['map'] = theme('gmap', array('#settings' => $vars['map_object']));

Also, in my case what I wanted instead was for duplicate locations to be "nudged" apart from each other, so here is a preprocess function that achieves that (based on FreddieK's code):

function mythemename_preprocess_gmap_view_gmap(&$vars) {
/**
 * Fixes the problem of multiple markers appearing on the same spot.
 */

  // set up the 2 for loops to be more efficient (never compare the same 2 markers twice)
  for ($outer=0; $outer < count($vars['map_object']['markers']); $outer++) {
    $outer_place =& $vars['map_object']['markers'][$outer];
    for ($inner = $outer+1; $inner < count($vars['map_object']['markers']); $inner++) {
      $inner_place =& $vars['map_object']['markers'][$inner];

      if ($outer_place['latitude'] == $inner_place['latitude'] && 
        $outer_place['longitude'] == $inner_place['longitude']) {
          // nudge the location of the inner place
          $inner_place['latitude'] += 0.01;
          $inner_place['longitude'] += 0.01;
        }
    }
  }

  // Theme the map.
  $vars['map'] = theme('gmap', array('#settings' => $vars['map_object']));
}
Exploratus’s picture

I am trying to put in the code in Template and ina custon module, and i get:

Cannot redeclare template_preprocess_gmap_view_gmap

It seems since gmap declares it, i cant redeclare it. How did you guys get around this?

rooby’s picture

Status: Active » Closed (duplicate)

This is a duplicate of #284481: GMap Views - show distinct markers or links for places with same lat/long

I know there is some work in this issue but it is very old and wouldn't work with the latest version of gmap.
There is a more recent patch in the other issue and it is the older issue.

If you still prefer the approach done here (I haven't looked into what it actually does) please do an updated version and post it to the other issue.

mry4n’s picture

Subscribe

commonpike’s picture

#27 did the trick, but i had to modify it quite a lot. I liked the approach though.

first, I needed to comment

// Theme the map.
// $vars['map'] = drupal_render($vars['map_element']);

at line 1400 in gmap.module (function template_preprocess_gmap_view_gmap).
this is a hack :-/

after that i could add #27 code to my themes template.php, but with some changes:

function MYTHEME_preprocess_gmap_view_gmap(&$vars) {
	/**
	* Fixes the problem of multiple markers appearing on the same spot.
	* http://drupal.org/node/530328
	*/
	
	// set up the 2 for loops to be more efficient (never compare the same 2 markers twice)
	for ($outer=0; $outer < count($vars['map_object']['markers']); $outer++) {
		$cc=0;
		$outer_place =& $vars['map_object']['markers'][$outer];
		for ($inner = $outer+1; $inner < count($vars['map_object']['markers']); $inner++) {
			$inner_place =& $vars['map_object']['markers'][$inner];
			if ($outer_place['latitude'] == $inner_place['latitude'] && 
				$outer_place['longitude'] == $inner_place['longitude']) {
					$cc++;
					// nudge the location of the inner place
					$inner_place['latitude'] += -0.05*sqrt($cc)*sin($cc*45);
					$inner_place['longitude'] += -0.05*sqrt($cc)*cos($cc*45);
				}
		}
	}

	// Theme the map - didnt work.
	// $vars['map'] = theme('gmap', array('#settings' => $vars['map_object']));
	
	$vars['map_element'] = array(
		'#type' => 'gmap',
		'#gmap_settings' => $vars['map_object'],
	);
	// Theme the map.
	$vars['map'] = drupal_render($vars['map_element']);
	  
}

You may notice the changes at the bottom - a different version of GMap I guess.
I also changed the logic in nudging the markers, so they spiral outward from their original position (I had like 10 marker with the same lat/long :-))

$2c
*-pike

ikeigenwijs’s picture

If everything else fails, i ll trie this hack,
But this looks also promising: http://drupal.org/node/1139088#comment-4961888

thtas’s picture

I've worked around this with some simple module code using hook_gmap. no need to hack anything.
drupal 6.x


function MYMODULE_gmap($op, &$map)
{
    if($op == 'pre_theme_map')
    {
        foreach($map['markers'] as $marker)
        {            
            $key = $marker['latitude']."|".$marker['longitude'];
                
            $marker_text[$key] .= $marker['text'];
            $marker_groups[$key] = $marker;
            $marker_groups[$key]['text'] = $marker_text[$key];
        }
            
        $map['markers'] = array_values($marker_groups);    
    }
}
ikeigenwijs’s picture

@ thtas
Can you explain what you did ?
You just made a custim module with this code? .module, .info
An did that the trick?

I use gmap for i while now, but due to an update i have the following problem:
Not all the nodes on the same location are beeing shown, apears to be limited to 2

thx a lot.

thtas’s picture

Yeah this code was part of a larger custom module, but at minimum it would just be a .module and .info file.

Not sure about the 2 item limit - have you checked the gmap view to make sure it's not paging or something?

ikeigenwijs’s picture

I found it, the locations with 3 or more all had an lat/long of 0.

jjbellamy’s picture

thtas,

After some research on the site for this issue, I like what you are proposing here. I have the same problem, showing multiple nodes with same latitude/longitude (city) on a single map. However, not sure how to implement your proposed codes. Should it be added to a module (gmap.module?) or as a new module? I am not a drupal programmer but can get around! Thanks a million for your help.

thtas’s picture

@jjbellamy,

You would need to have a custom module. e.g.

create a folder called jjbellamy, then inside create two files:

jjbellamy/jjbellamy.module
which contains the contents of the code in my post above, except with the word MYMODULE, replaced by jjbellamy,

AND

jjbellamy/jjbellamy.info
which contained the following:

; $Id$
name = jjbellamy
description = Custom functions for jjbellamy!
core = 6.x

Then upload and enabled your module.

for more info on how to create a custom module, see http://drupal.org/node/416986

jjbellamy’s picture

Thanks a lot thtas. I was able to install both files into a custom sub-folder in all/module. I enabled the module. However, when I try to view my map I get an error message (same if I go to GMap settings). The message says
warning: Missing argument 2 for caidc_gmap() in /home/caidc/public_html/sites/all/modules/custom_caidc/caidc.module on line 2. I copied straight from this thread. is there something I do wrong? or need to customize the line (function caidc_gmap($op, &$map))?

Thanks for your help.

webservant316’s picture

subscribe - need to fix this asap also.

jjbellamy’s picture

I finally was able to change the template file as per comment #51 at http://drupal.org/node/284481#comment-4997500. Good it works.

webservant316’s picture

Here is the solution I went with - http://drupal.org/node/1139088#comment-5956720. Works great for me.