Search code examples
phpmysqlgeolocationlevenshtein-distance

PHP MySQL - Levenshtein alternative on decimal


I have a data set with latitude and longitude coordinates (two separate decimal columns). I need to perform a search on them and order them by proximity, based on a supplied lat/lon coordinate.

I am not opposed to converting the columns to a varchar to perform a match/against search, but I know that the match/against is optimized for words.

What would be the best way to sort coordinates by distance? I can do this via PHP if necessary, though I would prefer to do it at the object layer to reduce server load and load times.

I am currently in the process of testing the match/against approach.

Sum up:

Given -90.23, 13.18 return the closest matching latitude/longitude coordinate pairs in order of proximity.

Sample result:

[1] -90.24, 13.17
[2] -90.18, 12.99
[3] -91.78, 16.98
[4] -90.27, 24.78

Solution

  • There are numerous methods to calculate geographic distance between sets of points. Some are accurate where others are fast. Which method you choose is all depends on your requirements. As there are many answered questions here at Stack Overflow which have specific answers:

    https://stackoverflow.com/search?tab=votes&q=distance%20mysql