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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
s:908:"<?xml version="1.0" encoding="UTF-8" ?>
<searchresults timestamp='Thu, 01 Oct 26 00:53:25 +0530' attribution='https://locationiq.com/attribution' querystring='10 Downing Street, London, United Kingdom' polygon='false'>
<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'>
<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>";
37 changes: 36 additions & 1 deletion 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 @@ -84,7 +86,40 @@ public function testGetNodeStreetName(): void

/** @var Location $result */
$result = $results->first();
$this->assertInstanceOf(\Geocoder\Model\Address::class, $result);
$this->assertInstanceOf(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(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);
}
}
Loading