Select to view content in your preferred language

geocoder dijit JS v3.4 returns duplicate candidates in autosuggest

1102
6
Jump to solution
04-05-2013 10:27 AM
DerekMiller
Deactivated User
Hello all,

Has anyone noticed that the geocoder dijit using the default Esri World Geocoder returns duplicate candidates in the auto-suggest list? Is this a compound locator that is returning 1 candidate from two locators, perhaps?

I'm not doing anything fancy.

var geocoder = new esri.dijit.Geocoder({         map: map,         autoComplete: true,         arcgisGeocoder: {             url: "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",             name: "Esri World Geocoder",             placeholder: "Find addresses",             suffix: " Portland, OR",             searchExtent: searchExtent,             sourceCountry: "USA"         }         //geocoders: geocoders,         //arcgisGeocoder: true     }, "address");      geocoder.startup();      dojo.connect(geocoder, "onSelect", showR);


The function showR simply returns graphics for the result.

You can view the app here: http://www.portlandbps.com/gis/solar/index.html

I suggest 1900 sw 4th ave as the search string. You'll notice the duplicate suggestions.

I'd like to either fix this or know that it's the expected behavior before I embed this map on our production site.

Thanks, and looking forward to your thoughts
0 Kudos
1 Solution

Accepted Solutions
MattDriscoll
Esri Contributor
I think you should be able to do something like:

connect.connect(myGeocoder, "onAutoComplete", function(results){      // modify results     var newResults = results;      myGeocoder.set('results', newResults);  });

View solution in original post

0 Kudos
6 Replies
JohnGravois
Deactivated User
if you look at the REST response you can see that "1900 Sw 4th Ave" is returned by the geocoding services rooftop locator and "1900 SW 4th Ave" is returned by the streets locator. 

Strangely, Using "1901" as an address doesn't cause the same behavior...

you could probably use the widget event onAutoComplete to loop through the results and compare them in all caps to remove duplicates, but i'd probably be pretty cool if we did that in the widget source code instead.
0 Kudos
DerekMiller
Deactivated User
you could probably use the widget event onAutoComplete to loop through the results and compare them in all caps to remove duplicates, but i'd probably be pretty cool if we did that in the widget source code instead.


I see that now in the response. I'm going to try your onAutoComplete suggestion. Once I loop through the results and remove any dups, how would you suggest passing the new result object back to the dijit suggestion auto-complete box?

Thanks again,

- d
0 Kudos
JohnGravois
Deactivated User
good question. 🙂
0 Kudos
MattDriscoll
Esri Contributor
I think you should be able to do something like:

connect.connect(myGeocoder, "onAutoComplete", function(results){      // modify results     var newResults = results;      myGeocoder.set('results', newResults);  });
0 Kudos
DerekMiller
Deactivated User
I think you should be able to do something like:

connect.connect(myGeocoder, "onAutoComplete", function(results){

    // modify results
    var newResults = results;

    myGeocoder.set('results', newResults);

});


John, Matt, thanks for the tips. I was able to get this to work using the code below.

dojo.connect(geocoder, "onAutoComplete", function (results) {
      var length = results.results.length;
      var testArray = [];
      var newResults = [];
      for (var i = 0; i < length; i++) {
        switch(i)
        {
        case 0:
          testArray.push(results.results.name.toUpperCase());
          newResults.push(results.results);
          break;
         default:
          var name = results.results.name;
          if (dojo.indexOf(testArray, name.toUpperCase()) === -1) {
            newResults.push(results.results);
          }
        }
      }
      geocoder.set('results', newResults);
 });


You can view the app without the dups at the following link if you want: http://www.portlandbps.com/gis/solar/index.html

1900 SW 4th Ave no longer returns 2 hits.

Thanks again,

- d
0 Kudos
MattDriscoll
Esri Contributor
Glad you got it working! :cool:
0 Kudos