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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.