Hi,
I really like the Gmap node location block. I however allow multiple locations per node, but only one location comes up in this block. I tried to work around this by making a gmap _view for the node, but never managed to make this work. Now I'm quite new to Drupal but am not scared to get my hands dirty. I've got the devel.module and when I load the node in Dev load view I see that the node has two arrays associated with it, one being "location", and the other being "locations" - is there any way to access these either in the view or in the blocks?

Thanks in advance for your help.
Kehan

Comments

astroboy’s picture

Component: Documentation » Code
Category: support » bug

I've changed themodule a bit, to it now displays multiple locations: here is my code (its not formatted cleanly but it works, i'll leav it up to you guys to make a proper patch)

replace function _gmap_location_getlatlon with :

function _gmap_location_getlatlon($node) {
  if(isset($node->locations)&&count($node->locations)>1){ //check if we havemultiple locations
	$locations =array();
	foreach($node->locations as $location){ //for each found, check if it's valid
		if(isset($location['longitude'])){
			array_push($locations,$location);
		}
	}
	return $locations;

  } else
  if (isset($node->location['latitude']) && isset($node->location['longitude'])) {
    return $node->location;
  }
  return false;
}

replace function gmap_location_map_add_node() with:


function gmap_location_map_add_node($basemap, $node, $label='') {
	drupal_set_message(print_r($node,true));
  $locations = _gmap_location_getlatlon($node);

  $markername = variable_get('gmap_node_marker_'.$node->type, '');
  $newmarkers = array();

  if($locations && !isset($locations['longitude'])){ //multiple locations have been found, change the data structure
	foreach($locations as $location){
	  $newmarker['latitude'] = $location['latitude'];
	  $newmarker['longitude'] = $location['longitude'];
	  $newmarker['markername']= $markername;
	  $newmarker['label']=$label;
	  array_push($newmarkers,$newmarker);
	}
	$location = $locations[0]; //so "backwards compatibility" is preserved;
  } else {
	$location = $locations; //Single location, like before
    $newmarker['latitude'] = $location['latitude'];
	$newmarker['longitude'] = $location['longitude'];
    $newmarker['markername']=variable_get('gmap_node_marker_'.$node->type, '');
    $newmarker['label']=$label;
    array_push($newmarkers,$newmarker);

  }

  if (empty($basemap['markers'])) {
    $thismap['markers']=array();
  }

  $basemap['markers'] = $newmarkers;
  $basemap['latitude'] = $location['latitude'];
  $basemap['longitude'] = $location['longitude'];
  return $basemap;
}

kehan’s picture

StatusFileSize
new28.75 KB

Nice! thanks a lot. I've reformatted the code and have attached the patch.

attiks’s picture

StatusFileSize
new17.3 KB

update to display multiple locations on map/node and map/node/xxx
WARNING: this will break the special handling of og nodes!!!

change in function gmap_location_node_page

1/ $thismap = gmap_location_node_map($n, $thismap, TRUE);
2/ $thismap = gmap_location_node_map($n, $thismap, FALSE);

into

1/ $thismap = gmap_location_map_add_node($thismap, $n);
2/ $thismap = gmap_location_map_add_node($thismap, $n);

change in function gmap_location_map_add_node

  if (empty($basemap['markers'])) {
    $thismap['markers']=array();
  }

  $basemap['markers'] = $newmarkers;

into

  if (empty($basemap['markers'])) {
    $basemap['markers']=array();
  }

  //$basemap['markers'] = $newmarkers;
  $basemap['markers'] = array_merge ($basemap['markers'], $newmarkers);
attiks’s picture

StatusFileSize
new17.65 KB

New updated patch that will add label (node->title) and click event to the markers

attiks’s picture

StatusFileSize
new17.65 KB

Sorry, fix for comment #4, i used $newmarker['autoclick'] = true; but this will open the text right away

fishhaddock1’s picture

Version: 5.x-1.x-dev » 6.x-1.0

Hello... I have the same issue with gmap for drupal 6.x ... when there are more than one locations in a node, the gmap block does not display both locations. The problem is that those functions in the drupal 5 patch do not exist for drupal 6 version.. the module must have been extensively rewritten??

toledo’s picture

I would like to have another gmap block with a different location on a different page.

How can I make more than one block with another location for another page/node?

toledo’s picture

I figured it out. Didn't have the right admin screen up. Dumb.

johnv’s picture

Status: Active » Closed (won't fix)

Closing this very old issue. Please reopen if it is still valid.