I have a 10.3 Geocode Server with suggest enabled, and trying to upgrade my applications with the geocoder widget using 3.12 JS API. Previous versions (10.2 Server and 3.11 API) worked great with auto suggest and auto navigate, and the Esri's world geocoding service plays very nicely with the geocoder widget at 3.12 (particularly like the highlightLocation feature), but everything seems broken with a custom GeocodeServer. Autosuggest doesn't work, auto navigate doesn't work even when you choose an exact match, etc. etc. Is this supposed to work with the geocode widget or do we have to write custom functionality (using the suggest and grabbing the magickey and then doing single line input). Seems like 10.3 has come slightly ahead of 3.12 API - do we have to wait until 3.13 or 4.0 for this to be fixed, or is it a bug?
Here is my source code:
<!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>Geocoder Widget</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
#search {
display: block;
position: absolute;
z-index: 2;
top: 20px;
left: 75px;
}
</style>
<script src="http://js.arcgis.com/3.12/"></script>
<script>
var map;
var geocoder;
var locatorUrl = "http:myserver:6080/arcgis/rest/services/Locators/AirportsGeocode/GeocodeServer";
require([
"esri/map", "esri/dijit/Geocoder", "dojo/domReady!"
], function(
Map, Geocoder
) {
map = new Map("map",{
basemap: "dark-gray",
center: [-97,38], // lon, lat
zoom: 5
});
var myGeocoders = [{
url: locatorUrl,
name: "AirportsGeocode",
singleLineFieldName: "SingleKey"
}];
geocoder = new Geocoder({
map: map,
autoComplete: true,
autoNavigate: true,
showResults: true,
highlightLocation: true,
maxLocations: 5,
minCharacters: 2,
arcgisGeocoder: false,
geocoders: myGeocoders,
value: "LAX"
},"search");
geocoder.startup();
});
</script>
</head>
<body>
<div id="search"></div>
<div id="map"></div>
</body>
</html>
Hi Jay,
Could you try setting suggest:true on your locator? That should get the autocomplete working.
var myGeocoders = [{ url: locatorUrl, name: "AirportsGeocode", suggest: true, singleLineFieldName: "SingleKey" }];
Thanks Matt - that certainly enabled the suggestion menu.
However, the autoNavigate functionality won't work. The entire map goes blank and I get a console error:
Error: Invalid value for <image> attribute x="NaN"
Error: Invalid value for <image> attribute y="NaN"
The REST Endpoint returns correct coords if I use it directly (although when building the geocoder, I didn't manually specific (x,y) like you can at 10.3). I assume the default of just taking the (x,y) from the SHAPE field would do. Anyway, thoughts here? Stilling using the same code as above, except with the "suggest" parameter.
Hey Jay,
Could you post the network response JSON from when a find occurs? It seems like the response may be missing something.
Thanks
From the findAddressCandidates endpoint, the result is:
{
"spatialReference" : {
"wkid" : 102100,
"latestWkid" : 3857
},
"candidates" : [{
"address" : "LAX",
"location" : {
"x" : -13181126.409301052,
"y" : 4021083.6552447858
},
"score" : 100,
"attributes" : {},
"extent" : {
"xmin" : "NaN",
"ymin" : "NaN",
"xmax" : "NaN",
"ymax" : "NaN"
}
}
]
}
So it's passing in web mercator aux spatial reference. Query string parameters (taken from the network response) are:
My 10.3 GeocodeServer however does have a spatial reference of 4326.
So I imagine the spatial reference parameter needs to be changed somehow.
What's strange is if I use Esri's World Geocoding Service instead in the geocoder widget, it also returns coords in 3857 coordinates, but the map knows how to handle it. That is, using the World Geocoding Service doesn't have the same effect - it works as expected.
It looks like it's because the extent has values that are NaN. Is there a way you can either remove the extent or set the values?
All that's automatic - I'd have to get access to the response before the geocoder dijit returns it to the map and either compute and extent or remove it. In the geocoder dijit documentation, there is a zoomScale attribute which claims: "Scale to zoom to when geocoder does not return an extent." I tried adding this attribute when instantiating the geocoder dijit but it doesn't seem to have any effect.
I'd have to change the actual geocoder (the one from which the service was created). There are optional fields you can specify on creation for the four extent coordinates, but I'd have to modify the source table, add four fields, figure out the best extent coords, etc. etc. Seems like a lot of work.....
Thoughts?
Is the JSON above from the geocoder widget? If so, can you send the actual network response from the network tab of the debugger tools? It would be interesting to see what the network is returning during a search. It may not be returning geometry or something it needs and that's why the extent is being set to NaN.
Is there anyway you can share the service URL so I could take a look?
Sorry if that was confusing. All the JSON is the network response from the network tab of the debugger tools. There are two network calls when using the Geocoder Widget.
1. When I start typing something, the network tab of the debugger tools shows a query to the "suggest" endpoint of my GeocodeService. This returns suggestions and a magicKey.
2. Then when I choose a result from the geocoder widget's drop down menu in the UI, the network tab shows a request to the "findAddressCandidates" endpoint of my GeocodeService. The JSON above is the response from that request, and the response shows that there is no extent returned and the spatial reference is incorrect (at least based on the spatial reference of my GeocodeService).
Unfortunately the service is behind our firewall so it's not public.
Hope that clears t hings up....