wincen Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/ Share on other sites More sharing options...
dave420 Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/#findComment-471521 Share on other sites More sharing options...
Sulman Posted February 20, 2008 Share Posted February 20, 2008 I have done this with PHP and MS SQL sproc (not MySQL). To be honest I didn't see much difference but I never benchmarked so daves suggestion above is a good way to go. Link to comment https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/#findComment-471525 Share on other sites More sharing options...
wincen Posted February 20, 2008 Author Share Posted February 20, 2008 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! Link to comment https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/#findComment-472031 Share on other sites More sharing options...
revraz Posted February 20, 2008 Share Posted February 20, 2008 If it happens so fast you can't see the difference, then does it matter? Link to comment https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/#findComment-472042 Share on other sites More sharing options...
Barand Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92076-calculating-distance-from-latlon-in-php-or-mysql/#findComment-472067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.