<script> dojo.require("esri.map"); dojo.require("esri.tasks.locator"); dojo.require("dojo.number"); dojo.require("dijit.form.Button"); dojo.require("dijit.form.Textarea"); dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.layers.FeatureLayer"); var map; function init() { map = new esri.Map("map", { basemap: "topo", center: [-68.95921478269354, 12.201009750494986], zoom: 11 }); var opLayer1 = new esri.layers.ArcGISDynamicMapServiceLayer( "ihavetherightlinkbutcannotputithere/rest/services/FeatureServer", { opacity:0.4, basemap:"topo" }); map.addLayer(opLayer1); var locator = new esri.tasks.Locator("http://ihavetherightlinkbutcannotputithere/rest/services/FeatureServer"); dojo.connect(locator, "onAddressToLocationsComplete", showResults); map.infoWindow.resize(200,125); } function locate() { map.graphics.clear(); var address = {"SingleLine":dojo.byId("Adres").value}; locator.outSpatialReference= map.spatialReference; var Adres = { address:Adres, } locator.addressToLocations(Adres); } function showResults(candidates) { var candidate; var symbol = new esri.symbol.SimpleMarkerSymbol(); var infoTemplate = new esri.InfoTemplate( "Address: ${Adres}"); symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE); symbol.setColor(new dojo.Color([153,0,51,0.75])); var geom; dojo.every(candidates,function(candidate){ console.log(candidate.Adres); var attributes = { address: candidate.Adres }; geom = candidate.Adres; var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate); //add a graphic to the map at the geocoded location map.graphics.add(graphic); //add a text symbol to the map listing the location of the matched address. var displayText = candidate.Adres; var font = new esri.symbol.Font("16pt",esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL,esri.symbol.Font.WEIGHT_BOLD,"Helvetica"); var textSymbol = new esri.symbol.TextSymbol(displayText,font,new dojo.Color("#666633")); textSymbol.setOffset(0,8); map.graphics.add(new esri.Graphic(geom, textSymbol)); return false; //break out of loop after one candidate with score greater than 80 is found. }); if(geom !== undefined){ map.centerAndZoom(geom,12); } } dojo.ready(init); </script>
Solved! Go to Solution.
var locator = new esri.tasks.Locator("http://ihavetherightlinkbutcannotputithere/rest/services/FeatureServer");
geom = candidate.location; ... //first make sure that the geometry of the returned address is actually defined if(geom !== undefined){ map.centerAndZoom(geom,12); }