hi i am creating a mashup in django and google maps and i am wondering if there is a way of clustering markers on the server side using django/python.
A:
I came up with the code below to figure out if one marker is close enough to another for clustering - close if two cluster icons start overlapping. Works for the whole world map for all zoom levels.
The problem is that map projection is non-linear and you can't just set some delta_lang
delta_lat
tolerance - both will depend on the lattitude. For local maps it is not a problem though.
If you want to do all on the server side you will have to calculate clustered markers for each zoomlelvel either per AJAX call or print them all at once.
function isCloseTo($other,$z){//$z is zoomlevel
$delta_lat = abs($this->lattitude - $other->lattitude);
$delta_lng = abs($this->longitude - $other->longitude);
$l = abs($this->lattitude);
$l2 = $l*$l;
$l3 = $l2*$l;
$l4 = $l3*$l;
$factor = 1
+0.0000312*$l
+0.0003604*$l2
-0.000009858*$l3
+0.0000001506*$l4;
$tol_lat = (45.42*exp(-0.6894339*$z)/3)/$factor;
$tol_lng = 21.845*exp(-0.67686*$z)/2;
if ($delta_lat < $tol_lat and $delta_lng < $tol_lng){
return true;
}
else{
return false;
}
}
Evgeny
2009-07-15 17:23:06
doesn't look very pythonic...
lhahne
2009-08-07 11:43:31
that's php :) but hopefully you can figure out the translation :)
Evgeny
2009-08-07 15:34:50