Skip to content

Commit 59c2a21

Browse files
zero0cool0Patrick Fischer
andauthored
Fix coordinates order on calling setBounds() in LocationIQ.php (#1273)
* Fix coordinate order for setBounds in LocationIQ.php * test: add LocationIQ bounds test * test: add cached test response * refactor: php-cs-fixer fixes --------- Co-authored-by: Patrick Fischer <gandalf11@gmail.com>
1 parent 432f5bd commit 59c2a21

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎src/Provider/LocationIQ/LocationIQ.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN
154154
if ($boundsAttr) {
155155
$bounds = [];
156156
list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr);
157-
$builder->setBounds((float) $bounds['south'], (float) $bounds['north'], (float) $bounds['west'], (float) $bounds['east']);
157+
$builder->setBounds((float) $bounds['south'], (float) $bounds['west'], (float) $bounds['north'], (float) $bounds['east']);
158158
}
159159

160160
return $builder->build();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
s:908:"<?xml version="1.0" encoding="UTF-8" ?>
2+
<searchresults timestamp='Thu, 01 Oct 26 00:53:25 +0530' attribution='https://locationiq.com/attribution' querystring='10 Downing Street, London, United Kingdom' polygon='false'>
3+
<place place_id='278575488' osm_type='relation' osm_id='1879842' boundingbox="51.5033074,51.5036913,-0.1277991,-0.1273088" lat='51.5034878' lon='-0.1276965' display_name='10 Downing Street, 10, Downing Street, Westminster, Covent Garden, City of Westminster, England, SW1A 2AA, United Kingdom' class='office' type='government' importance='0.55057445391694'>
4+
<government>10 Downing Street</government><house_number>10</house_number><road>Downing Street</road><quarter>Westminster</quarter><suburb>Covent Garden</suburb><city>City of Westminster</city><state>England</state><postcode>SW1A 2AA</postcode><country>United Kingdom</country><country_code>gb</country_code></place></searchresults>";

‎src/Provider/LocationIQ/Tests/LocationIQTest.php‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Geocoder\Collection;
1616
use Geocoder\IntegrationTest\BaseTestCase;
1717
use Geocoder\Location;
18+
use Geocoder\Model\Address;
19+
use Geocoder\Model\Bounds;
1820
use Geocoder\Provider\LocationIQ\LocationIQ;
1921
use Geocoder\Query\GeocodeQuery;
2022
use Geocoder\Query\ReverseQuery;
@@ -84,7 +86,40 @@ public function testGetNodeStreetName(): void
8486

8587
/** @var Location $result */
8688
$result = $results->first();
87-
$this->assertInstanceOf(\Geocoder\Model\Address::class, $result);
89+
$this->assertInstanceOf(Address::class, $result);
8890
$this->assertEquals('Rue Quincampoix', $result->getStreetName());
8991
}
92+
93+
public function testCorrectBounds(): void
94+
{
95+
$provider = new LocationIQ($this->getHttpClient($_SERVER['LOCATIONIQ_API_KEY']), $_SERVER['LOCATIONIQ_API_KEY']);
96+
97+
$results = $provider->geocodeQuery(GeocodeQuery::create('10 Downing Street, London, United Kingdom'));
98+
99+
$this->assertInstanceOf(\Geocoder\Model\AddressCollection::class, $results);
100+
$this->assertCount(1, $results);
101+
102+
/** @var Address $result */
103+
$result = $results->first();
104+
105+
$this->assertInstanceOf(Address::class, $result);
106+
$this->assertEquals('Downing Street', $result->getStreetName());
107+
$this->assertEquals('United Kingdom', $result->getCountry()->getName());
108+
109+
/** @var Bounds $bounds */
110+
$bounds = $result->getBounds();
111+
112+
$north = $bounds->getNorth();
113+
$south = $bounds->getSouth();
114+
$west = $bounds->getWest();
115+
$east = $bounds->getEast();
116+
117+
$this->assertTrue($north > $south);
118+
$this->assertTrue($east > $west);
119+
120+
$this->assertEqualsWithDelta(51.5033074, $south, 1E-6);
121+
$this->assertEqualsWithDelta(51.5036913, $north, 1E-6);
122+
$this->assertEqualsWithDelta(-0.1277991, $west, 1E-6);
123+
$this->assertEqualsWithDelta(-0.1273088, $east, 1E-6);
124+
}
90125
}

0 commit comments

Comments
 (0)