Skip to content

Commit

Permalink
⚡️ Enhance locationiq - formattedAddress, county, unify country name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tokyo authored Oct 20, 2024
1 parent 3d661ee commit c684196
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/geocoder/locationiqgeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,31 @@ LocationIQGeocoder.prototype._reverse = function(query, callback) {
LocationIQGeocoder.prototype._formatResult = function(result) {
// transform lat and lon to real floats
var transformedResult = {
'latitude' : result.lat ? parseFloat(result.lat) : undefined,
'longitude' : result.lon ? parseFloat(result.lon) : undefined
latitude : result.lat ? parseFloat(result.lat) : undefined,
longitude : result.lon ? parseFloat(result.lon) : undefined,
};

if (result.display_name) {
transformedResult.formattedAddress = result.display_name;
}

if (result.address) {
transformedResult.country = result.address.country;
transformedResult.country = result.address.country;
transformedResult.city = result.address.city || result.address.town || result.address.village || result.address.hamlet;
transformedResult.state = result.address.state;
transformedResult.zipcode = result.address.postcode;
transformedResult.streetName = result.address.road || result.address.cycleway;
transformedResult.streetNumber = result.address.house_number;

if (transformedResult.county) {
transformedResult.county = result.address.county;
}

// make sure countrycode is always uppercase to keep node-geocoder api formats
var countryCode = result.address.country_code;
if (countryCode) {
countryCode = countryCode.toUpperCase();
}

transformedResult.countryCode = countryCode;
}
return transformedResult;
Expand Down

0 comments on commit c684196

Please sign in to comment.