PHP Levenshtein distance

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

{{{ lang=php line=1
$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]]


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *