Tutorial :server side marker clustering in django


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.


I have implemented server side clustering in Django on my real estate/rentals site; I explain it here.


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;      }  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »