I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Friday, September 23, 2011

Calculate distance between two points with MySQL

This function here is the right one. It returns pretty same results as the Google Maps distance, which leads me to believe that it's kind of correct.


I've seen a lot of ready solutions online for the same input/output/platform combination (i.e. WGS84 degrees input/output on MySQL), but all of them used some other formula (at the end multiplying by 1.1515) that was producing some results that never worked for me.

On the other hand the following formula returns results identical with what Google Maps returns.
My function output

Cross check
Apparently there's some issue with the bearing and that's why the result is still not precisely accurate, but it's much closer than the other methods' outputs I've tried before.