Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Provider/LocationIQ/LocationIQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN
if ($boundsAttr) {
$bounds = [];
list($bounds['south'], $bounds['north'], $bounds['west'], $bounds['east']) = explode(',', $boundsAttr);
$builder->setBounds((float) $bounds['south'], (float) $bounds['north'], (float) $bounds['west'], (float) $bounds['east']);
$builder->setBounds((float) $bounds['south'], (float) $bounds['west'], (float) $bounds['north'], (float) $bounds['east']);
}

return $builder->build();
Expand Down
35 changes: 35 additions & 0 deletions src/Provider/LocationIQ/Tests/LocationIQTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Geocoder\Collection;
use Geocoder\IntegrationTest\BaseTestCase;
use Geocoder\Location;
use Geocoder\Model\Address;
use Geocoder\Model\Bounds;
use Geocoder\Provider\LocationIQ\LocationIQ;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
Expand Down Expand Up @@ -87,4 +89,37 @@ public function testGetNodeStreetName(): void
$this->assertInstanceOf(\Geocoder\Model\Address::class, $result);
$this->assertEquals('Rue Quincampoix', $result->getStreetName());
}

public function testCorrectBounds(): void
{
$provider = new LocationIQ($this->getHttpClient($_SERVER['LOCATIONIQ_API_KEY']), $_SERVER['LOCATIONIQ_API_KEY']);

$results = $provider->geocodeQuery(GeocodeQuery::create('10 Downing Street, London, United Kingdom'));

$this->assertInstanceOf(\Geocoder\Model\AddressCollection::class, $results);
$this->assertCount(1, $results);

/** @var Address $result */
$result = $results->first();

$this->assertInstanceOf(\Geocoder\Model\Address::class, $result);
$this->assertEquals('Downing Street', $result->getStreetName());
$this->assertEquals('United Kingdom', $result->getCountry()->getName());

/** @var Bounds $bounds */
$bounds = $result->getBounds();

$north = $bounds->getNorth();
$south = $bounds->getSouth();
$west = $bounds->getWest();
$east = $bounds->getEast();

$this->assertTrue($north > $south);
$this->assertTrue($east > $west);

$this->assertEqualsWithDelta(51.5033074, $south, 1E-6);
$this->assertEqualsWithDelta(51.5036913, $north, 1E-6);
$this->assertEqualsWithDelta(-0.1277991, $west, 1E-6);
$this->assertEqualsWithDelta(-0.1273088, $east, 1E-6);
}
}