1
var searchWidget = new Search({
  view: view,
  includeDefaultSources:false
  sources: [{
    locator: new Locator({ url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"}),
    countryCode:"GB",
    categories:["Address", "Postal"],
    maxResults: 10
    minSuggestCharacters: 4,
    placeholder:"Find address",
    filter:{
        ...
    }
  }]
});

I'm trying to limit the results to a certain geographical area. I've been told I can use the filter property, but I can't find how or any examples.

1

The filter object can have a geometry or where property. The full specification for this object can be found here. So for example if you want to filter to the USA lower 48 states you might send in a Polygon into the geometry property like this:

filter: {
  geometry: new Polygon({
    "rings": [
      [
        [
          -124.60937499999179,
          48.17147426999536
        ],
        [
          -110.5468749999955,
          49.33038796569682
        ],
        [
          -66.0742187500073,
          48.17147426999536
        ],
        [
          -70.99609375000601,
          24.454504932416402
        ],
        [
          -125.66406249999149,
          30.682664491952345
        ],
        [
          -124.60937499999179,
          48.17147426999536
        ]
      ]
    ],
    "spatialReference": {
      "wkid": 4326
    }
  })
}

See the working example here. To see it in action, search "Rome" with the filter in place, and then without.

Note that even if you're sending in a Polygon like I am above, it is translated into a rectangle bounding box because that is what the Geocoding service accepts.

  • My search is returning results outside of the polygon (about 1 km around the edges) for some reason, is there any way to force it not to? – RedHorse Oct 10 '18 at 9:51
  • @RedHorse After investigating this more, what is happening here is that even though you're sending in a Polygon for the filter, that Polygon is translated into a rectangle bounding box "Extent" since that is what the /suggest endpoint on the Esri Geocoder accepts: developers.arcgis.com/rest/geocode/api-reference/… .. So that's why you're seeing additional results. – GavinR Oct 11 '18 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.