From 2a058fa5299aabdc638bb61417d0dc7f7f99652c Mon Sep 17 00:00:00 2001 From: moczka Date: Mon, 24 Oct 2016 17:32:55 -0400 Subject: [PATCH 1/3] Adding a regExp test before calling the .geocode() method for a second time --- app/scripts/app.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/scripts/app.js b/app/scripts/app.js index c2bd820..b723ac2 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -226,7 +226,8 @@ require(['jquery', // if there are no results, try searching for Cambridge if (!results.length) { - geocoder.geocode({ address: address + ' Cambridge, MA' }, function(results, status) { + if((/cambridge+/i).test(address)){ + geocoder.geocode({ address: address + ' Cambridge, MA' }, function(results, status) { results = $.grep(results, addressIsCambridgeStreetAddress); if (!results.length) { $('#notice') @@ -236,7 +237,12 @@ require(['jquery', displaySearchResults(results); google.maps.event.trigger(map, 'resize'); } - }); + }); + }else{ + $('#notice') + .addClass('error') + .html($('#noLocation').text()); + } } else { displaySearchResults(results); google.maps.event.trigger(map, 'resize'); From 31037284ffd4d9a5bf05d2214a1c6ebc56a3863a Mon Sep 17 00:00:00 2001 From: moczka Date: Mon, 24 Oct 2016 17:50:51 -0400 Subject: [PATCH 2/3] Making the regExp test better by making sure it is followed by MA as to avoid streets named cambridge --- app/scripts/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/app.js b/app/scripts/app.js index b723ac2..8a9cbd6 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -226,7 +226,7 @@ require(['jquery', // if there are no results, try searching for Cambridge if (!results.length) { - if((/cambridge+/i).test(address)){ + if((/cambridge, ma+/i).test(address)){ geocoder.geocode({ address: address + ' Cambridge, MA' }, function(results, status) { results = $.grep(results, addressIsCambridgeStreetAddress); if (!results.length) { From 3e27e8616362f035dd59ab3e97011ef474b7f155 Mon Sep 17 00:00:00 2001 From: moczka Date: Tue, 25 Oct 2016 15:59:10 -0400 Subject: [PATCH 3/3] Improving the regular expression even further by considering multiple white space and optional commas --- app/scripts/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/app.js b/app/scripts/app.js index 8a9cbd6..baf2be6 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -226,7 +226,7 @@ require(['jquery', // if there are no results, try searching for Cambridge if (!results.length) { - if((/cambridge, ma+/i).test(address)){ + if((/(cambridge,?\s*ma)+/i).test(address)){ geocoder.geocode({ address: address + ' Cambridge, MA' }, function(results, status) { results = $.grep(results, addressIsCambridgeStreetAddress); if (!results.length) {