Hi,

I want to center a gmap view on coordinates passed by views arguments arg(1) and arg(2).

So I am trying to apply the php filter to the gmap macro in gmap.module

Around line 347 I change

 function gmap_parse_macro($instring, $ver = 2) {
  require_once drupal_get_path('module', 'gmap') . '/gmap_parse_macro.inc'; 

into

 function gmap_parse_macro($instring, $ver = 2) {
  $instring=check_markup($instring, 3, FALSE);
  require_once drupal_get_path('module', 'gmap') . '/gmap_parse_macro.inc'; 

(without php tags)

And my macro gets to be
echo "[gmap|zoom=4|width=300px|height=200px|center=".arg(1).",".arg(2)."]"; (with php tags)

All that works fine.

But as I have 800 locations I want to filter with the proximity filter, on the proximity.

So in filters I select "Location: Distance / Proximity" and a static latitude and longitude. As values I tried arg(1); and echo arg(1); but none of them work.

I tried to include the php filter in location.views

    case 'static':
      $coordinates['latitude'] = (float) $options['latitude'];
      $coordinates['longitude'] = (float) $options['longitude'];
      break;

into

    case 'static':
      $coordinates['latitude'] = (float) check_markup($options['latitude'], 3, FALSE);
      $coordinates['longitude'] = (float) check_markup($options['longitude'], 3, FALSE);
      break;

but no avail.... almost there, tips? anyone?

Comments

eiland’s picture

Status: Active » Needs review

my bad, there's just a php filter for proximity, so

its just

 return(array(
'latitude' => arg(1),
'longitude' =>arg(2)
));

change status to needs review because of applying php filter in gmap.module

eiland’s picture

Title: How to apply arguments in proximity filter to gmap view? » How to alter gmap macro with php

the coordinates are of course not passed by arg(1) and arg(2) but by

 $view = views_get_current_view();
echo "[gmap|zoom=14|width=100%|height=300px|center=".$view->args[0].",".$view->args[1]."]"; 

ill probably set the zoom level too with an argument.

eiland’s picture

Beware, it is important that the filter format chosen in $instring=check_markup($instring, 3, FALSE); Where 3 represents the filter item as in /admin/settings/filters, is PHP only, so no GMAP macro filter. That will break the function and show the default map instead.

alanpeart’s picture

Your simple fix here (adding the PHP filter to the GMap macro) just saved my life! I needed to center the map on a postcode argument and this did the trick, thank you.

joomtech’s picture

could you please guide me more how to do that? For instant, what should be in the view path such as localhost/testview/10.123123,20.2313 ???

And which module files needed to be modified?

Thank you very much!

eiland’s picture

Have you tried localhost/testview/10.123123/20.2313

so with a slash between the arguments?

And you only modify the gmap.module file.

joomtech’s picture

Thank you very much for your answer. I have solved the problem already.

landing’s picture

sub

andrea.cavattoni’s picture

i 'm doing the same thing but with smart ip, and i cant understand why, but it's not working, i just get an zoom error message in the map.
i'm using this code:

 echo "[gmap zoom=8  |width=700px |height=400px  |type=Map |behaviour=-overview |control=None |center=" $_SESSION['smart_ip']['location']['latitude'].",".$_SESSION['smart_ip']['location']['longitude']."]"; 

someone can help me?

eiland’s picture

seems you forgot the dot (.) between center=" and $_SESSION

andrea.cavattoni’s picture

mmm yep, but still not working:

<?php
echo "[gmap zoom=4  |width=700px |height=400px  |type=Map |behaviour=-overview |control=None |center=".$_SESSION['smart_ip']['location']['latitude'].",".$_SESSION['smart_ip']['location']['longitude']."]"; 
?>

if i print it with php in the tpl works fine, dont know what's wrong with this code.

agileware’s picture

Status: Needs review » Active

Changing status - no patch to review.

Probably should add this to the views style instead of the macro function.

agileware’s picture

It also shouldn't rely on the PHP input format.
The number 3 will not always be the PHP filter and the PHP filter module may not be installed.

andrea.cavattoni’s picture

Status: Active » Needs review

Php filter is installed, and the php macro extend too, dont know,
also this one isn't working:

http://envisioninteractive.com/drupal/user-targeted-content-with-drupal-...

andrea.cavattoni’s picture

Hi At list i had to change gmap_parse_macro.inc

Righe : 61->65

if(module_exists('php')) {
$instring = php_eval($instring);
}

dabeer’s picture

I've managed to apply php filter to gmap by modifying gmap.module.

I'm trying to use php to set zoom in Gmap macro with:

$zoom = 7;
echo "[gmap | control=Small | width=100% | zoom=".$zoom."]"

The code works fine, which proves php is working.

However, I would like to apply different zoom for individual nodes. So each node that has a location stores the desired zoom level in an integer field (field_zoom).

I cannot figure out how to retrieve the value of the field_zoom with php so that I can use it in the Gmap macro. I've tried:

$zoom = $node->field_zoom[0]["value"];
echo "[gmap | control=Small | width=100% | zoom=".$zoom."]"

but it does not work.

Can anyone point me in the right direction?

podarok’s picture

Status: Needs review » Active

right statuses