AnsweredAssumed Answered

Address Locator Example Documentation

Question asked by nathalieneagle on May 2, 2012
Latest reply on May 3, 2012 by esrijay
I can get the address locator working in my app using the ESRI locator but once I flip the locator over to point at my service it doesn't work. I'm having trouble with figuring out what the parameters are and if they should be changed. I tried to look at the example rest endpoint of ESRI's locator but it seems like there are address requested and return fields not present or Don't match up.


I was hoping to highlight the inputs in red and maybe someone can tell me what they point to so I can figure out if I need to change that input or not:


function locate() {
        map.graphics.clear();
// The singleLine I believe is coming from the find address candidate from the REST  SingleLine (Type: esriFieldTypeString, Alias: Single Line Input, Required: false ) but where is address coming from  -- also for the singleline should I use single line or my alias because my alias is different and ESRI's is not
        var address = {"SingleLinee":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);
        }

      }



Also I'm trying to check my server and machine communication with fiddle and I can see I make the request and the address candidates are sent back from the server but then I'm not sure where my code is failing. I'm new to JS and I'm use to IDEs that allow for debugging...how should I go about and debug with JS
Thanks
Nathalie

Outcomes