Skip to content

Commit f3225ad

Browse files
authored
[LocationIQ] Normalize City (#1038)
* Update LocationIQ.php Add `normalizecity` parameter in the request to make sure there is a `city` property in the response. See https://locationiq.com/docs-html/index.html#locationiq-specific-parameters Close #1037 * Update LocationIQ.php Fix issue if `country_code` is not defined. * Update tests and cached responses * Update IntegrationTest.php Apply fixes from StyleCI * Migrate to format `xmlv1.1` See documentation: https://locationiq.com/docs-html/index.html#response-format-forward * Update LocationIQ.php Apply fixes from StyleCI
1 parent 4d3facf commit f3225ad

21 files changed

+32
-30
lines changed

src/Provider/LocationIQ/LocationIQ.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN
135135
$builder->setLocality($this->getNodeValue($addressNode->getElementsByTagName('city')));
136136
$builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb')));
137137
$builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country')));
138-
$builder->setCountryCode(strtoupper($this->getNodeValue($addressNode->getElementsByTagName('country_code'))));
139138
$builder->setCoordinates($resultNode->getAttribute('lat'), $resultNode->getAttribute('lon'));
140139

140+
$countryCode = $this->getNodeValue($addressNode->getElementsByTagName('country_code'));
141+
if (!is_null($countryCode)) {
142+
$builder->setCountryCode(strtoupper($countryCode));
143+
}
144+
141145
$boundsAttr = $resultNode->getAttribute('boundingbox');
142146
if ($boundsAttr) {
143147
$bounds = [];
@@ -173,12 +177,12 @@ private function executeQuery(string $url, string $locale = null): string
173177

174178
private function getGeocodeEndpointUrl(): string
175179
{
176-
return self::BASE_API_URL.'/search.php?q=%s&format=xml&addressdetails=1&limit=%d&key='.$this->apiKey;
180+
return self::BASE_API_URL.'/search.php?q=%s&format=xmlv1.1&addressdetails=1&normalizecity=1&limit=%d&key='.$this->apiKey;
177181
}
178182

179183
private function getReverseEndpointUrl(): string
180184
{
181-
return self::BASE_API_URL.'/reverse.php?format=xml&lat=%F&lon=%F&addressdetails=1&zoom=%d&key='.$this->apiKey;
185+
return self::BASE_API_URL.'/reverse.php?format=xmlv1.1&lat=%F&lon=%F&addressdetails=1&normalizecity=1&zoom=%d&key='.$this->apiKey;
182186
}
183187

184188
private function getNodeValue(\DOMNodeList $element)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
s:533:"<?xml version="1.0" encoding="UTF-8" ?>
2+
<reversegeocode timestamp='Thu, 09 Jan 20 02:26:20 +0530' attribution='https://locationiq.com/attribution' querystring='format=xmlv1.1&amp;lat=0.000000&amp;lon=0.000000&amp;addressdetails=1&amp;normalizecity=1&amp;zoom=18&amp;key=d4146b4eba1a69'>
3+
<result place_id="49118199" osm_type="node" osm_id="3815077900" lat="0" lon="0" boundingbox="-0.0001,0.0001,-0.0001,0.0001">Atlas Buoy 0.00E 0.00N</result><addressparts><address29>Atlas Buoy 0.00E 0.00N</address29></addressparts></reversegeocode>";

src/Provider/LocationIQ/Tests/.cached_responses/locationiq.org_494a2d59bf1ccd08b0bf695cb18b52506a61a05d

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/Provider/LocationIQ/Tests/.cached_responses/locationiq.org_550b92b9cee41341f094605b3108b64c8831c3f4

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
s:1646:"<?xml version="1.0" encoding="UTF-8" ?>
2+
<searchresults timestamp='Thu, 09 Jan 20 02:25:52 +0530' attribution='https://locationiq.com/attribution' querystring='10 Downing St, London, UK' polygon='false'>
3+
<place place_id='223123428' boundingbox="51.5032573,51.5036483,-0.1278356,-0.1273038" lat='51.50344025' lon='-0.127708209585621' display_name='Prime Minister’s Office, 10, Downing Street, St. James&#039;s, Covent Garden, Westminster, London, Greater London, England, SW1A 2AA, United Kingdom' class='tourism' type='attraction' importance='0.89147137691773' icon='https://locationiq.org/static/images/mapicons/poi_point_of_interest.p.20.png'>
4+
<attraction>Prime Minister’s Office</attraction><house_number>10</house_number><road>Downing Street</road><neighbourhood>St. James's</neighbourhood><suburb>Covent Garden</suburb><city>London</city><state_district>Greater London</state_district><state>England</state><postcode>SW1A 2AA</postcode><country>United Kingdom</country><country_code>gb</country_code></place><place place_id='18958984' boundingbox="51.5032302,51.5033302,-0.1276858,-0.1275858" lat='51.5032802' lon='-0.1276358' display_name='10, Downing Street, St. James&#039;s, Covent Garden, Westminster, London, Greater London, England, SW1, United Kingdom' class='place' type='house' importance='0.421'>
5+
<house_number>10</house_number><road>Downing Street</road><neighbourhood>St. James's</neighbourhood><suburb>Covent Garden</suburb><city>London</city><state_district>Greater London</state_district><state>England</state><postcode>SW1</postcode><country>United Kingdom</country><country_code>gb</country_code></place></searchresults>";

src/Provider/LocationIQ/Tests/.cached_responses/locationiq.org_661bba330195fbdaf5b9bce7ee3f755000fba114

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Provider/LocationIQ/Tests/.cached_responses/locationiq.org_681cc4febee1d743c2b1c1449b99d6e322eb42c2

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)