elove

Find An Address: Locate is not a function

Discussion created by elove on Aug 31, 2012
Latest reply on Sep 5, 2012 by elove
Hi,

I am trying to implement the "Find An Address" sample in my JavaScript map and keep getting an error in the Chrome console that reads "locate is not a function". I am using the ESRI locator in my code. Any ideas what I am doing wrong?

Thanks!

// Added for Locator Service    
 locator = new esri.tasks.Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
         dojo.connect(locator, "onAddressToLocationsComplete", showResults);
   
   
   
    function locate() {
         map.graphics.clear();
         var address = {"SingleLineInput":dojo.byId("address").value};
         locator.outSpatialReference= map.spatialReference;
         var options = {
           address:address,
           outFields:["Loc_name"]
         }
         locator.addressToLocations(options);
       }
 
function showResults(candidates) {
         var candidate;
         var symbol = new esri.symbol.SimpleMarkerSymbol();
         var infoTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}");
 
        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.score);
           if (candidate.score > 80) {
             console.log(candidate.location);
             var attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name };   
            geom = candidate.location;
             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.address;
             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);
         }
 
      }
  
   


  
    <div dojoType="dijit.layout.ContentPane" id="addressPane" title="Find Address"> 
 Enter an input address and the application will use the sample address locator to return the location for 
        street addresses in the United States. 
        <br />
         <textarea type="text" id="address"/>2001 S. State Street, SLC, UT</textArea>
         <br />
         <button dojotype="dijit.form.Button" onclick="locate()"> Locate</button> 
      </div>

Outcomes