Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Do you actually need to calculate the <a href="http://en.wikipedia.org/wiki/Euclidean_distance" rel="noreferrer">Euclidean distance</a>? If you are just comparing relative magnitudes of distances, you can probably get away with using the <a href="http://en.wikipedia.org/wiki/Manhattan_distance" rel="noreferrer">Manhattan distance</a>, which will save you two calls to <code>pow()</code> and one to <code>sqrt()</code>: </p> <pre><code>function pixelDistance($lat1, $lon1, $lat2, $lon2, $zoom) { $x1 = $lon1*10000000; //This is what I did to compensate for using lat/lon values instead of pixels. $y1 = $lat1*10000000; $x2 = $lon2*10000000; $y2 = $lat2*10000000; return ($x1-$x2) + ($y1-$y2) &gt;&gt; (21 - $zoom); } </code></pre> <p>Not sure if you need the <code>>> (21 - $zoom)</code> bit for your calculations, so I left it in. But unless you actually need to use the calculated distance values elsewhere, you can probably get away with just using the latitude/longitude directly (no need to multiply by anything) and taking the Manhattan distance, assuming you pre-calculate <code>$distance</code> to fit in with that measure, which will be a lot cheaper in computational terms than coercing all the distances to fit in with the units and magnitude of <code>$distance</code>.</p> <p>EDIT: When I was researching this problem last year, I found some useful stuff on Wikipedia - yes, it can happen ;-)</p> <ul> <li><a href="http://en.wikipedia.org/wiki/Cluster_analysis" rel="noreferrer">Cluster analysis</a></li> <li><a href="http://en.wikipedia.org/wiki/Hierarchical_clustering" rel="noreferrer">Hierarchical clustering</a></li> </ul> <p>I can also highly recommend the book <em><a href="http://www.amazon.co.uk/Programming-Collective-Intelligence-Building-Applications/dp/0596529325/ref=sr_1_5?ie=UTF8&amp;s=books&amp;qid=1253123239&amp;sr=1-5" rel="noreferrer">Programming Collective Intelligence: Building Smart Web 2.0 Applications </a></em> which goes into clustering in great depth, as applied not only to geographical data but also to other areas of data analysis.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload