From f42136c3aa54f7e0d3b54d24fe531163ab092288 Mon Sep 17 00:00:00 2001 From: Neha Rathi Date: Tue, 27 Feb 2024 08:08:13 -0500 Subject: [PATCH 1/4] Update openstreetmapgeocoder.js --- lib/geocoder/openstreetmapgeocoder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/openstreetmapgeocoder.js b/lib/geocoder/openstreetmapgeocoder.js index be0f90aa..d3c3dbbe 100644 --- a/lib/geocoder/openstreetmapgeocoder.js +++ b/lib/geocoder/openstreetmapgeocoder.js @@ -68,7 +68,7 @@ OpenStreetMapGeocoder.prototype._geocode = function(value, callback) { OpenStreetMapGeocoder.prototype._formatResult = function(result) { - var countryCode = result.address.country_code; + var countryCode = result.address?.country_code; if (countryCode) { countryCode = countryCode.toUpperCase(); } From 83648fad062554be513d34c7855459b4186266b0 Mon Sep 17 00:00:00 2001 From: Neha Rathi Date: Tue, 27 Feb 2024 08:12:07 -0500 Subject: [PATCH 2/4] Update openstreetmapgeocoder.js --- lib/geocoder/openstreetmapgeocoder.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/geocoder/openstreetmapgeocoder.js b/lib/geocoder/openstreetmapgeocoder.js index d3c3dbbe..bb7bbb6e 100644 --- a/lib/geocoder/openstreetmapgeocoder.js +++ b/lib/geocoder/openstreetmapgeocoder.js @@ -87,14 +87,14 @@ OpenStreetMapGeocoder.prototype._formatResult = function(result) { 'latitude' : latitude, 'longitude' : longitude, 'formattedAddress': result.display_name, - 'country' : result.address.country, - 'city' : result.address.city || result.address.town || result.address.village || result.address.hamlet, - 'state': result.address.state, - 'zipcode' : result.address.postcode, - 'streetName': result.address.road || result.address.cycleway, - 'streetNumber' : result.address.house_number, + 'country' : result.address?.country, + 'city' : result.address?.city || result.address?.town || result.address?.village || result.address?.hamlet, + 'state': result.address?.state, + 'zipcode' : result.address?.postcode, + 'streetName': result.address?.road || result.address?.cycleway, + 'streetNumber' : result.address?.house_number, 'countryCode' : countryCode, - 'neighbourhood': result.address.neighbourhood || '' + 'neighbourhood': result.address?.neighbourhood || '' }; }; From 30f40d7583a91946411e861ec781eaf94a18e43f Mon Sep 17 00:00:00 2001 From: Neha Rathi Date: Tue, 27 Feb 2024 17:18:14 -0500 Subject: [PATCH 3/4] Update openstreetmapgeocoder.js --- lib/geocoder/openstreetmapgeocoder.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/geocoder/openstreetmapgeocoder.js b/lib/geocoder/openstreetmapgeocoder.js index bb7bbb6e..2f03e559 100644 --- a/lib/geocoder/openstreetmapgeocoder.js +++ b/lib/geocoder/openstreetmapgeocoder.js @@ -68,7 +68,7 @@ OpenStreetMapGeocoder.prototype._geocode = function(value, callback) { OpenStreetMapGeocoder.prototype._formatResult = function(result) { - var countryCode = result.address?.country_code; + var countryCode = result.address == null ? undefined : result.country_code; if (countryCode) { countryCode = countryCode.toUpperCase(); } @@ -87,14 +87,14 @@ OpenStreetMapGeocoder.prototype._formatResult = function(result) { 'latitude' : latitude, 'longitude' : longitude, 'formattedAddress': result.display_name, - 'country' : result.address?.country, - 'city' : result.address?.city || result.address?.town || result.address?.village || result.address?.hamlet, - 'state': result.address?.state, - 'zipcode' : result.address?.postcode, - 'streetName': result.address?.road || result.address?.cycleway, - 'streetNumber' : result.address?.house_number, + 'country' : result.address == null ? undefined : result.address.country, + 'city' : result.address == null ? undefined : result.address.city || result.address.town || result.address.village || result.address.hamlet, + 'state': result.address == null ? undefined : result.address.state, + 'zipcode' : result.address == null ? undefined : result.address.postcode, + 'streetName': result.address == null ? undefined : result.address.road || result.address.cycleway, + 'streetNumber' : result.address == null ? undefined : result.address.house_number, 'countryCode' : countryCode, - 'neighbourhood': result.address?.neighbourhood || '' + 'neighbourhood': result.address == null ? '' : result.address.neighbourhood || '' }; }; From 4ab6f3f4bfa59349988e0e9d5c727c7ebe82972e Mon Sep 17 00:00:00 2001 From: Neha Rathi Date: Wed, 28 Feb 2024 18:38:32 -0500 Subject: [PATCH 4/4] Update openstreetmapgeocoder.js --- lib/geocoder/openstreetmapgeocoder.js | 49 ++++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/geocoder/openstreetmapgeocoder.js b/lib/geocoder/openstreetmapgeocoder.js index 2f03e559..1d0a7fc9 100644 --- a/lib/geocoder/openstreetmapgeocoder.js +++ b/lib/geocoder/openstreetmapgeocoder.js @@ -67,34 +67,35 @@ OpenStreetMapGeocoder.prototype._geocode = function(value, callback) { }; OpenStreetMapGeocoder.prototype._formatResult = function(result) { - - var countryCode = result.address == null ? undefined : result.country_code; - if (countryCode) { - countryCode = countryCode.toUpperCase(); - } - - var latitude = result.lat; - if (latitude) { - latitude = parseFloat(latitude); + var countryCode, latitude, longitude, formattedAddress, country, city, state, zipcode, streetName, streetNumber, neighbourhood; + + if (result.address) { + countryCode = result.address.country_code ? result.address.country_code.toUpperCase() : undefined; + country = result.address.country; + city = result.address.city || result.address.town || result.address.village || result.address.hamlet; + state = result.address.state; + zipcode = result.address.postcode; + streetName = result.address.road || result.address.cycleway; + streetNumber = result.address.house_number; + neighbourhood = result.address.neighbourhood || ''; } - var longitude = result.lon; - if (longitude) { - longitude = parseFloat(longitude); - } + latitude = result.lat ? parseFloat(result.lat) : undefined; + longitude = result.lon ? parseFloat(result.lon) : undefined; + formattedAddress = result.display_name; return { - 'latitude' : latitude, - 'longitude' : longitude, - 'formattedAddress': result.display_name, - 'country' : result.address == null ? undefined : result.address.country, - 'city' : result.address == null ? undefined : result.address.city || result.address.town || result.address.village || result.address.hamlet, - 'state': result.address == null ? undefined : result.address.state, - 'zipcode' : result.address == null ? undefined : result.address.postcode, - 'streetName': result.address == null ? undefined : result.address.road || result.address.cycleway, - 'streetNumber' : result.address == null ? undefined : result.address.house_number, - 'countryCode' : countryCode, - 'neighbourhood': result.address == null ? '' : result.address.neighbourhood || '' + 'latitude': latitude, + 'longitude': longitude, + 'formattedAddress': formattedAddress, + 'country': country, + 'city': city, + 'state': state, + 'zipcode': zipcode, + 'streetName': streetName, + 'streetNumber': streetNumber, + 'countryCode': countryCode, + 'neighbourhood': neighbourhood }; };