Hi,
Why is it that if I send this text 500 boulevard des laurentides to the Geocoder service, then it will only return these two matches:
500 Boulevard des Laurentides, Laval, Québec, CAN
500 Boulevard des Laurentides, Vimont, Québec, CAN
The address I'm looking for is this:
500 Boulevard des Laurentides, Saint-Jérôme, Québec, CAN
But the Geocoder won't offer this result unless I specify the city too.
The street name text is an exact match, why is it not returned initially?
I don't get it. Is there something wrong in my options?
Here is my code:
this.searchAddressGeocoder = new Geocoder({
arcgisGeocoder: {
url: '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
outFields: "*",
searchExtent: new Extent(
{
xmin: -8500000,
ymin: 5600000,
xmax: -8000000,
ymax: 6150000,
spatialReference: {
wkid: 102100
}
}
),
sourceCountry: "CA",
suffix: " ,Quebec",
categories: ['Address']
},
autoComplete: true,
autoNavigate: false,
geocoderMenu: true,
map: this.map,
maxLocations: 6,
minCharacters: 3,
searchDelay: 350, // milliseconds
theme: "simpleGeocoder",
//highlightLocation: true,
localSearchOptions: {
},
onSelect: lang.hitch(this, this.onGeocoderAddressSelect)
}, "searchAddress-geocoder");
Thanks
Edit: Another question. Is there a way to specify a point, and have the Geocoder prefer results near that point ?
Solved! Go to Solution.
It looks like you can use the local search options. If you specify a distance and minScale in local search options the widget will use the map extent center and the specified distance when the map scale is less than the specified min scale. If I add this to my test code and run you can see the location and distance params are used in the suggest request.
var s = new Search({ map: map }, "search"); var locator = s.sources[0]; locator.searchExtent = map.extent; //location search using map.extent.getCenter and the specified //distance will be performed when the map scale //is less than minScale. locator.localSearchOptions = { distance: 5000, //in meters minScale: 5000000 }; s.startup();
It appears the suffix might have been to blame. Since the real name of the province of Quebec is written Québec, I suspect some algorithms and/or databases are not accent insensitive. So I tried just using Qu instead (avoiding the accented character altogether in the suffix) and now the address I'm looking for is returned properly.
My second question remains though. My search extent is a vast territory, and I have to be able to search all of it. However it's likely most of the address searches will be in a much smaller area. I wish I could define a point and have the Geocoder favor results near that point. I read something about this ArcGIS REST API: World Geocoding Service documentation but can't see any way to do this with this dijit.
Thanks again
Looks like you can specify distance and location on the locator to weight the returned results. The API ref has details:
Locator | API Reference | ArcGIS API for JavaScript
So you should be able to specify a location and distance option when you setup the locator for the Search widget.
Hi Kelly.
It doesn't appear so, unless I misunderstand what you mean. I can specify location and distance in functions called by a Locator task, but I can't create a locator where you specify those values and tell the dijit to use it. I don't see how.
I modified my code to use my own locator, but the location and distance values are ignored and not included in the request. Also it generates a findAddressCandidates request instead of a suggest request
this.geocoders = [{
url: '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
searchExtent: new Extent(
{
xmin: -8500000,
ymin: 5600000,
xmax: -8000000,
ymax: 6150000,
spatialReference: {
wkid: 102100
}
}
),
outFields: "*",
sourceCountry: "CA",
localSearchOptions: {
location: new Point(-8237582.87, 5746371.15, new SpatialReference({ wkid: 102100 })),
distance: 50000
}
}];
this.searchAddressGeocoder = new Geocoder({
geocoders: this.geocoders,
arcgisGeocoder: false,
autoComplete: true,
autoNavigate: false,
geocoderMenu: true,
map: this.map,
maxLocations: 6,
minCharacters: 3,
searchDelay: 350, // milliseconds
theme: "simpleGeocoder",
//highlightLocation: true,
localSearchOptions: {
},
onSelect: lang.hitch(this, this.onGeocoderAddressSelect)
}, "searchAddress-geocoder");
Request sent:
It looks like you can use the local search options. If you specify a distance and minScale in local search options the widget will use the map extent center and the specified distance when the map scale is less than the specified min scale. If I add this to my test code and run you can see the location and distance params are used in the suggest request.
var s = new Search({ map: map }, "search"); var locator = s.sources[0]; locator.searchExtent = map.extent; //location search using map.extent.getCenter and the specified //distance will be performed when the map scale //is less than minScale. locator.localSearchOptions = { distance: 5000, //in meters minScale: 5000000 }; s.startup();
Ok I see. Unfortunately the map center does not correspond to the location I need, but I understand how it works now.
In any case I did some tests with a Locator task using a specific location point and I didn't see any much improvement anyway. For instance even if I specify the locator should prefer results near a point located in a specific city, and I enter a street name I know exists in that city, sometimes I won't even get it in the results, I'll get results for similar street names in cities hundreds of kilometers away. So I think we'll stick with the Geocoder dijit for now and instead try to educate the client that they really should enter the city name if they want relevant results. Just entering a civic number and street name might sometimes work, but not always.
Thank you very much for your help.