Address Locator Example Documentation

1293
2
Jump to solution
05-02-2012 11:55 AM
NathalieNeagle
New Contributor III
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
0 Kudos
1 Solution

Accepted Solutions
JMcNeil
Occasional Contributor III
Nathalie,

Jeff is correct the address is the name of your user's text box and it is grabbing the text they input. If it works with the ESRI sample and doesn't work on yours then I would look at this line of code:

var address = {"SingleLine":dojo.byId("address").value};


Here you are setting a variable address to equal the value entered in your address textbox and assigning/passing that value to the "Single Line Input" address field rest point.  So if you look at the rest http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer/ or the JSON http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer/?f=pjson you will see the address field is named "SingleLine" and the alias is "Single Line Input"

In the ESRI example
var address = {"SingleLine":dojo.byId("address").value};
they are using the name "SingleLine" but I think you could also use the alias "Single Line Input"

I would check you rest and see what your address fields are named and/or the alias names and replace that with "SingleLine"

If I look at my rest I see:

AddressLoc102100 (GeocodeServer)
Service Description:

Address Fields:

    Street (Type: esriFieldTypeString, Alias: Street or Intersection, Required: true )

Single Line Address Field:

    Single Line Input (Type: esriFieldTypeString, Alias: Full Address, Required: false )

Candidate Fields:


So I could use these possibilities:

var address = {"Street":dojo.byId("address").value}; var address = {"Intersection":dojo.byId("address").value}; var address = {"Single Line Input":dojo.byId("address").value}; var address = {"Full Address":dojo.byId("address").value}; 



here's some more reading on dojo.byId
http://dojotoolkit.org/reference-guide/1.7/dojo/byId.html

Jay

View solution in original post

0 Kudos
2 Replies
JeffPace
MVP Alum
dojo.byId("address").value is saying look for a item in your HTML code with id="address" (this is likely an input text box) and get its value. Its in function locate, so that function is likely called with an onClick event to a search button.



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
0 Kudos
JMcNeil
Occasional Contributor III
Nathalie,

Jeff is correct the address is the name of your user's text box and it is grabbing the text they input. If it works with the ESRI sample and doesn't work on yours then I would look at this line of code:

var address = {"SingleLine":dojo.byId("address").value};


Here you are setting a variable address to equal the value entered in your address textbox and assigning/passing that value to the "Single Line Input" address field rest point.  So if you look at the rest http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer/ or the JSON http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer/?f=pjson you will see the address field is named "SingleLine" and the alias is "Single Line Input"

In the ESRI example
var address = {"SingleLine":dojo.byId("address").value};
they are using the name "SingleLine" but I think you could also use the alias "Single Line Input"

I would check you rest and see what your address fields are named and/or the alias names and replace that with "SingleLine"

If I look at my rest I see:

AddressLoc102100 (GeocodeServer)
Service Description:

Address Fields:

    Street (Type: esriFieldTypeString, Alias: Street or Intersection, Required: true )

Single Line Address Field:

    Single Line Input (Type: esriFieldTypeString, Alias: Full Address, Required: false )

Candidate Fields:


So I could use these possibilities:

var address = {"Street":dojo.byId("address").value}; var address = {"Intersection":dojo.byId("address").value}; var address = {"Single Line Input":dojo.byId("address").value}; var address = {"Full Address":dojo.byId("address").value}; 



here's some more reading on dojo.byId
http://dojotoolkit.org/reference-guide/1.7/dojo/byId.html

Jay
0 Kudos