AnsweredAssumed Answered

filtering Geocoder for a specific country

Question asked by dmarquardt on Jan 5, 2015
Latest reply on Jan 14, 2015 by filipkral

Hello,

 

I'm trying to filter esri's geocoder for a specific country.  I've had some success, but nothing works extremely well.  I would have thought simply adding sourceCountry = "xxx" to the parameters of the arcgisGeocoder would work, but I couldn't get it to zoom correctly.   here are the three versions I've found:

 

1. attach a condition to the URL

2. go with no filter

3. use suffix = ", USA"

 

I'm attaching a code snippet as well below of these.

 

I'm wondering: Has anyone found a better way to filter the autocomplete options and have the map zoom to the correct coordinates?

 

//1. this one works okay, but the autofill is much slower than the others

   

   var myGeocoders = [{

          url: "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer?sourceCountry=USA",

          name: "EsriWorldLocator",

          placeholder: "Find a place",

          autoComplete: true,

         singleLineFieldName: "SingleLine"

    }];

   

   

    var geocoder = new Geocoder ({

        map: map,

        arcgisGeocoder: false,

        geocoders: myGeocoders

        }, dom.byId("search")

        );

    geocoder.autoComplete = true;

   

 

    //2. This is the original, no filter

   

    var geocoder =  new Geocoder({

      arcgisGeocoder: {

     

        placeholder: "Find a place"

      },

      autoComplete: true,

      map: map

    }, dom.byId("search")

    );   

   

   

   

    //3.  This one has a great autocomplete, but it zooms to a seemingly random location

   

    var geocoder =  new Geocoder({

      arcgisGeocoder: {

        //sourceCountry: "USA",

        suffix: ", USA",

        placeholder: "Find a place"

      },

      autoComplete: true,

      autoNavigate: true,

      map: map

    }, dom.byId("search")

    );   

Outcomes