From e67a6dc32117bd1bd14e2d0cfbe978f74300e85f Mon Sep 17 00:00:00 2001 From: marc tobias Date: Tue, 19 Sep 2017 12:40:10 +0100 Subject: [PATCH] fix to NearPoint::extractFromQuery handling first minus sign --- lib/NearPoint.php | 4 ++-- test/php/Nominatim/NearPointTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/NearPoint.php b/lib/NearPoint.php index e8d595cc..4f0531d9 100644 --- a/lib/NearPoint.php +++ b/lib/NearPoint.php @@ -133,8 +133,8 @@ class NearPoint $sFound = $aData[0]; $fQueryLat = ($aData[2]=='N'?1:-1) * ($aData[1]); $fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[3]); - } elseif (preg_match('/(\\[|^|\\b)(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData)) { - /* 1 2 3 4 + } elseif (preg_match('/(\\[|^|\\b)?(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData)) { + /* 1 2 3 4 * degrees decimal * 12.34, 56.78 * [12.456,-78.90] diff --git a/test/php/Nominatim/NearPointTest.php b/test/php/Nominatim/NearPointTest.php index 6fa9b515..5ad73451 100644 --- a/test/php/Nominatim/NearPointTest.php +++ b/test/php/Nominatim/NearPointTest.php @@ -35,6 +35,10 @@ class NearPointTest extends \PHPUnit_Framework_TestCase $this->assertEquals($aRes['pt']->radius(), 0.1); $this->assertEquals($aRes['query'], ''); + $aRes = NearPoint::extractFromQuery(' -12.456,-78.90 '); + $this->assertEquals($aRes['pt']->lat(), -12.456); + $this->assertEquals($aRes['pt']->lon(), -78.90); + // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion // these all represent the same location $aQueries = array( -- 2.39.5