Below is my implementation of Levenshtein distance in PHP. This is useful to determine the distance between two latitude & longitude pairs.

1
2
3
4
5
6
7
8
$lat1 = deg2rad($location1->lat);
$lng1 = deg2rad($location1->lng);
$lat2 = deg2rad($location2->lat);
$lng2 = deg2rad($location2->lng);
$theta = $location1->lng - $location2->lng; 
$dist = sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos(deg2rad($theta)); 
$dist = acos($dist); 
$dist = rad2deg($dist) * 60 * 1.1515; // Miles

Credits

http://en.wikipedia.org/wiki/Levenshtein_distance

0