JS API: sourceCountry in Geocoder has no effect

6034
13
Jump to solution
08-20-2014 01:36 PM
JamesSampica
New Contributor

Using this sample...

ArcGIS API for JavaScript Sandbox

change the geocoder as follows...

 

    geocoder = new Geocoder({

          autoComplete: true,

          map: map ,

          arcgisGeocoder: {

                    sourceCountry: "USA"

                }

    }, "search");

 

typing anything into the geocoder still causes it to match addresses from other countries.

 

Is there a workaround for this?

0 Kudos
13 Replies
TracySchloss
Frequent Contributor

I'm not sure I understand exactly what Kelly is saying, but maybe there are parameters that are honored in the 'find', that are ignored at the point while it's still in 'suggest' mode?  I've tried several variations of sourceCountry and suffix as a parameter for my Geocoder definition, but nothing refines both the suggestions and returned results.  I ended up taking them out, because it didn't look like it was helping. 

In your screenshot, you are getting completely different suggestions compared to what I have seen.  Again, I have to wonder why.  Is it the scale threshold you're at when you enter the ZIP?  You're obviously not centered on Missouri, so it's not an extent.   Somewhere in the calls and responses something is broken.  Hopefully it will be fixed in the next release (the standard answer we all take with a grain of salt). 

0 Kudos
KellyHutchins
Esri Frequent Contributor

Tracy,

Correct at the current release there are some parameters (like searchExtent) that are honored by find but not suggest. After the next release of ArcGIS Online searchExtent will be honored by suggest so the suggestions you see will be limited to the search extent you provide. Support for sourceCountry should be available at a later date.

So for the next release try updating your app to specify a search extent. Doing so should make the provided suggestions more relevant.

Kelly

0 Kudos
Noah-Sager
Esri Regular Contributor

What do you get when you run this? I didn't modify anything except the "suffix" parameter.

<!DOCTYPE html>  
<html>  
  <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>  
    <title>Geocode Dijit</title>  
    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">  
    <style>  
      html, body, #map {  
        height:100%;  
        width:100%;  
        margin:0;  
        padding:0;  
      }  
      #search {  
        display: block;  
        position: absolute;  
        z-index: 2;  
        top: 20px;  
        left: 74px;  
      }  
    </style>  
    <script type="text/javascript">  
var djConfig = {  
  parseOnLoad: false  
};  
</script>  
    <script src="http://js.arcgis.com/3.11/"></script>  
    <script>  
      var map, geocoder;  
    require(["dojo/parser","esri/map", "esri/dijit/Geocoder", "esri/layers/GraphicsLayer","esri/graphic",  
    "esri/symbols/SimpleMarkerSymbol","esri/InfoTemplate","dojo/_base/Color", "dojo/_base/array", "dojo/dom",  
    "esri/request", "dojo/domReady!"  
  ], function(  
    parser,Map,Geocoder,GraphicsLayer,Graphic,SimpleMarkerSymbol,InfoTemplate,Color,arrayUtils,dom,esriRequest  
        ) {  
        
        parser.parse();      
        
        // create the map  
        map = new Map("map",{  
          basemap: "topo",  
          center: [-92.593, 38.5],  
          zoom: 8,  
        });  
        
        // create the geocoder  
        var geocoder =  new Geocoder({  
          autoComplete: true,  
          map: map,  
          arcgisGeocoder: {  
            placeholder: "Find a place",  
            sourceCountry:"US",  
            suffix:", Missouri, USA"
          }   
        }, dom.byId("search"));  
        
        geocoder.startup();  
        geocoder.focus();  
        geocoder.on("select", showLocation);  
          
        var symbol = new SimpleMarkerSymbol();  
        symbol.setStyle(SimpleMarkerSymbol.STYLE_CIRCLE);   
        symbol.setColor(new Color([255,128,0,0.75]));    
        
        function showLocation(evt) {  
          map.graphics.clear();  
          var point = evt.result.feature.geometry;  
          var graphic = new Graphic(point, symbol);  
          map.graphics.add(graphic);  
  
  
       //   map.infoWindow.setTitle("Search Result");  
          map.infoWindow.setContent(evt.result.name);  
          map.infoWindow.show(evt.result.feature.geometry);  
        }  
  
  
       geocoder.on('clear', function (evt){  
          map.graphics.clear();  
          map.infoWindow.hide();  
         });  
        });  
  
  
    </script>  
  </head>  
  <body>  
    <div id="search"></div>  
    <div id="map"></div>  
  </body>  
</html>  
TracySchloss
Frequent Contributor

I'd say my results are still rather random.  For example, the zip 65043, works.  But that doesn't take care of everything.  When I try this address:  2727 N Main St, Sikeston, MO, 'suggest' offers that address.   Great, I think it's works! 

But, when I click to complete the search, it takes me to Missouri Valley, Iowa.   I'm sure that's a very nice place, but not the one I'm searching for.  There is definitely a difference between suggest and find. 

0 Kudos