Skip to content

Commit

Permalink
Merge pull request #211 from michaelpuzon/master
Browse files Browse the repository at this point in the history
handle empty array being returned by locationiq
  • Loading branch information
nchaulet authored Apr 9, 2017
2 parents b9d4e4b + 5813133 commit 1ef3916
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/geocoder/locationiqgeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ LocationIQGeocoder.prototype._geocode = function(value, callback) {
// when there’s no err thrown here the resulting array object always
// seemes to be defined but empty so no need to check for
// responseData.error for now

var results = responseData.map(this._formatResult).filter(function(result) {
return result.longitude && result.latitude;
});
results.raw = responseData;
// add check if the array is not empty, as it returns an empty array from time to time
var results = [];
if (responseData.length && responseData.length > 0) {
results = responseData.map(this._formatResult).filter(function(result) {
return result.longitude && result.latitude;
});
results.raw = responseData;
}

callback(false, results);
}.bind(this));
Expand Down

0 comments on commit 1ef3916

Please sign in to comment.