Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Enhance locationiq - formattedAddress, county, unify country name #335

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions lib/geocoder/locationiqgeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,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;
/* make sure country name is unified accross geocoders */
transformedResult.country = result.address.country === 'United States of America' ? 'United States' : result.address.country;
a-tokyo marked this conversation as resolved.
Show resolved Hide resolved
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;
}
a-tokyo marked this conversation as resolved.
Show resolved Hide resolved

// 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