Draw circle overlay in all points in gmap from Radius in a CCK field | Dynamic gmap Macro in Views

User login

Lately I needed to add a circle in every marker in a gmap provided by Views.

So in order to achieve this, I filled in the Macro textarea of the Style:Gmap settings of the View with the following code. But first, I added the field that contains the Radius value and excluded it from Display, to make the value available in the view result set. This value was in miles, so I made the conversion from km as well.

<?php
$circles
= array();
$view = views_get_current_view();
foreach (
$view->result as $result) {
$lat = $result->gmap_lat ;
$lon = $result->gmap_lon;
$radius = $result->the_cck_field_holding_the radius;
$radius = $radius*0.621371192;
array_push($circles, "circle=".$lat." ,".$lon." + ".$radius);
}
print
"[gmap ".implode('|', $circles)."]";
?>

However, for this to work, I needed to change the input format of this textarea in order to accept PHP, by editing the gmap.module file.

So according to http://drupal.org/node/954384 :

I needed to 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';
?>

Tags: 
Drupal 6, Drupal Quick Tips, Views