AnsweredAssumed Answered

How to filter Search widget results by State?

Question asked by wbw4sv on Dec 10, 2017
Latest reply on Dec 11, 2017 by rscheitlin

I'm wondering how I can filter the results of the search widget to only give me results in a certain state (say Washington for example). I've been able to filter by country, and by location type by modifying the "categories" and "countryCode" properties of the default Locator. I also found this website which seems like it is allowing me to filter by state by specifying the url: http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer?f=pjson&region=Washington. Navigating here with my browser works fine, however, when I use this as the URL for a locator, it doesn't filter anything out. I've tried several variations of this URL to no avail. This seems like something that should be possible so I figure I must be doing something wrong and was hoping somebody on here might be able to help me. Here's the full source code that initializes my search bar (sorry for lack of formatting - I don't see anything for inserting code snippets): 

var source ={
locator: new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?region=Virginia&f=json"),
singleLineFieldName: "SingleLine",
outFields: ["*"],
name: "",
localSearchOptions: {
minScale: 300000,
distance: 50000
},
placeholder: "",
highlightSymbol: new PictureMarkerSymbol(this.basePath + "/images/search-pointer.png", 36, 36).setOffset(9, 18)
}
var srcs = search.get("sources");
srcs[0] = source;
//srcs[0].locator.url = "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer?f=pjson&region=Washington";
//Restrict Search Results to US
srcs[0].countryCode = "US";
//Restrict Search Results to Locations in inital map display
srcs[0].searchExtent = extentInitial;
//Placeholder Text
srcs[0].placeholder = "Search for an area";
//Restricts searches to Neighborhood, City, Subregion, Region, Country, and Zone
//srcs[0].categories = ["Populated Place"];

search.set("sources", srcs);
search.startup();

Outcomes