Download & Extend

How to alter gmap macro with php

Project:GMap Module
Version:6.x-1.1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

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

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

into

<?php
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

<?php
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

<?php
arg
(1);
?>
and
<?php
echo arg(1);
?>
but none of them work.

I tried to include the php filter in location.views

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

into
<?php
   
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

#1

Status:active» needs review

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

its just

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

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

#2

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

<?php
$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.

#3

Beware, it is important that the filter format chosen in

<?php
$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.

#4

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.

#5

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!

#6

Have you tried localhost/testview/10.123123/20.2313

so with a slash between the arguments?

And you only modify the gmap.module file.

#7

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

#8

sub

#9

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?

#10

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

#11

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.

#12

Status:needs review» active

Changing status - no patch to review.

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

#13

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.

#14

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-...

#15

Hi At list i had to change gmap_parse_macro.inc

Righe : 61->65

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

#16

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:

<?php
$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:

<?php
$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?

#17

Status:needs review» active

right statuses