Skip to content

Commit fd18f10

Browse files
committed
Merge pull request #329 from toin0u/patch-mapquest
Patch MapQuest provider
2 parents 0271825 + d041314 commit fd18f10

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/Geocoder/Provider/MapQuestProvider.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,22 @@ protected function executeQuery($query)
144144
$results = array();
145145

146146
foreach ($locations as $location) {
147-
$results[] = array_merge($this->getDefaults(), array(
148-
'latitude' => $location['latLng']['lat'],
149-
'longitude' => $location['latLng']['lng'],
150-
'streetName' => $location['street'] ?: null,
151-
'city' => $location['adminArea5'] ?: null,
152-
'zipcode' => $location['postalCode'] ?: null,
153-
'county' => $location['adminArea4'] ?: null,
154-
'region' => $location['adminArea3'] ?: null,
155-
'country' => $location['adminArea1'] ?: null,
156-
));
147+
if ($location['street'] || $location['postalCode'] || $location['adminArea5'] || $location['adminArea4'] || $location['adminArea3'] || $location['adminArea1']) {
148+
$results[] = array_merge($this->getDefaults(), array(
149+
'latitude' => $location['latLng']['lat'],
150+
'longitude' => $location['latLng']['lng'],
151+
'streetName' => $location['street'] ?: null,
152+
'city' => $location['adminArea5'] ?: null,
153+
'zipcode' => $location['postalCode'] ?: null,
154+
'county' => $location['adminArea4'] ?: null,
155+
'region' => $location['adminArea3'] ?: null,
156+
'country' => $location['adminArea1'] ?: null,
157+
));
158+
}
159+
}
160+
161+
if (empty($results)) {
162+
throw new NoResultException(sprintf('Could not find results for given query: %s', $query));
157163
}
158164

159165
return $results;

tests/Geocoder/Tests/Provider/MapQuestProviderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ public function testGetGeocodedDataWithAddressGetsNullContent()
3636
$provider->getGeocodedData('10 avenue Gambetta, Paris, France');
3737
}
3838

39+
/**
40+
* @expectedException \Geocoder\Exception\NoResultException
41+
* @expectedExceptionMessage Could not find results for given query: http://open.mapquestapi.com/geocoding/v1/reverse?key=api_key&lat=123.000000&lng=456.000000
42+
*/
43+
public function testGetNotRelevantData()
44+
{
45+
$json = '{"results":[{"locations":[{"street":"","postalCode":"","adminArea5":"","adminArea4":"","adminArea3":"","adminArea1":""}]}]}';
46+
47+
$provider = new MapQuestProvider($this->getMockAdapterReturns($json), 'api_key');
48+
$provider->getReversedData(array(123, 456));
49+
}
50+
3951
public function testGetGeocodedDataWithRealAddress()
4052
{
4153
if (!isset($_SERVER['MAPQUEST_API_KEY'])) {

0 commit comments

Comments
 (0)