I am trying to use a composite geocoding service in a javascript web app, but it returns a result from each of the address locators (Address_Points & Street_Centerlines) referenced by the composite locator.
Is there a parameter I can set, somewhere, that tells the geocoder to return ONLY the BEST result?
Solved! Go to Solution.
Thanks for the help, Yue. I got some one-on-one help at the ESRI UC, and found a very simple solution.
All I needed to do was change one character...
from:
to:
Hi Craig,
There are several ways to limit the geocoder widget to return result:
One way to do it is to set maxLocations that returns after you typed the name of location, please take a look about this API reference: Geocoder | API Reference | ArcGIS API for JavaScript
The other way is to set some specifications for geocoder. Take a look this page https://developers.arcgis.com/javascript/jsapi/geocoder-amd.html#geocoder1 and search "Object Specifications" for details. It sounds like you are using your own custom geocoder, so you better to make sure if those all specifications are available for your geocoder.
Also, Here is a sample code to append suffix to restrict the result to "Redlands" Geocoder - append default suffix | ArcGIS API for JavaScript
There is another similar thread about geocoder suggestions you can take as a references filtering Geocoder for a specific country
Hope this can help!
Thanks Yue, it was helpful. I added maxLocations to the code, but it's still returning two results.
I'm not sure whether I added the parameter incorrectly or whether its not supported for this.
Would you say the following snippet looks right?
function locate() {
map.graphics.clear();
var add = dojo.byId("address").value;
var address = {
Street : add,
maxLocations : 1
};
locator.addressToLocations(address,["Loc_name"]);
}
Hi Craig,
One thing you can do is when you using the chrome and open the developer tools and check the network tab, every time when you type something on the search widget bar, you can find the web requests that generate from javascript client and make sure the maxLocations parameter is right as you put in code, sometimes you may put the wrong location and the parameter not honored.
Please take this snippet code as a reference:
You need to put the maxLocations under geocoder object not geocoders, the reason is because you add geocoders into geocoder to use your own composed geocoder.
var geocoders = [{ url: "http://nwu-win7.esri.com/server/rest/services/AtlantaGeolocator/GeocodeServer", name: "AtlantaGeolocator Geocoder", singleLineFieldName: "Single Line Input", autoComplete: true, }]; var geocoder = new Geocoder({ map: map, geocoders: geocoders, autoComplete: true, autoNavigate: true, minCharacters: 3, arcgisGeocoder: false, maxLocations: 1 },"search");
Thanks for the help, Yue. I got some one-on-one help at the ESRI UC, and found a very simple solution.
All I needed to do was change one character...
from:
to: