- return $address['text'];
- }
- return implode("\n", array_slice($textLines, 0, -1));
- }
-
- // Search for the lign from the given address that is the closest to the geocoded thoroughfareName
- // and replaces the corresponding lign in the geocoded text by it.
- static protected function fixStreetNumber(&$address)
- {
- if (isset($address['thoroughfareName'])) {
- $thoroughfareName = $address['thoroughfareName'];
- $thoroughfareToken = strtoupper(trim(preg_replace(array("/[,\"'#~:;_\-]/", "/\r\n/"),
- array("", "\n"), $thoroughfareName)));
- $geolocLines = explode("\n", $address['geoloc']);
- $textLines = explode("\n", $address['text']);
- $mindist = strlen($thoroughfareToken);
- $minpos = 0;
- $pos = 0;
- foreach ($textLines as $i => $token) {
- if (($l = levenshtein(strtoupper(trim(preg_replace(array("/[,\"'#~:;_\-]/", "/\r\n/"),
- array("", "\n"), $token))),
- $thoroughfareToken)) < $mindist) {
- $mindist = $l;
- $minpos = $i;
- }
- }
- foreach ($geolocLines as $i => $line) {
- if (strtoupper(trim($thoroughfareName)) == strtoupper(trim($line))) {
- $pos = $i;
- break;
- }
- }
- $geolocLines[$pos] = $textLines[$minpos];
- $address['geoloc'] = implode("\n", $geolocLines);