Jump to content

calculating distance from lat/lon in php or mysql?


wincen

Recommended Posts

What are the pros and cons of calculating distance from lat/lons in php vs calculating it in mysql?

 

I've been searching online and it appears that both are able to do so, but I have yet to find which is the preferred method.  Does one offer more accuracy?  Is it faster to do so in mysql and just return the distance?

I would suggest doing some benchmarking of the two different methods, and see which one is fastest.  They're both going to be as accurate as each other, so it comes down to speed.  Calculate a bunch of different distances in both methods and see which one returns fastest, then use that.

How do you run benchmarks on these calculations?  I've never done so and am curious to see the results.

 

Does anyone have tools they can suggest?

 

Thanks!

 

<?php
$t1 = microtime(true);
for($i=0; $i < 100; $i++)
{
    // do method 1
}

$t2 = microtime(true);
for($i=0; $i < 100; $i++)
{
    // do method 2
}

$t3 = microtime(true);

echo "Method 1 took ", $t2-$t1, '<br/>';
echo "Method 2 took ", $t3-$t2, '<br/>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.