gis_tech

Address Locator - what am I doing wrong?

Discussion created by gis_tech on Oct 12, 2011
Latest reply on Oct 13, 2011 by DSwingley-esristaff
Hello there.  I've got an Address Locator set up and it seems to be working.  When I go to the service properties and enter the address "202 Birch Loop", it returns results as expected:

http://restdata.umatilla.nsn.us/ArcGIS/rest/services/CTUIRAddressLocator/GeocodeServer/findAddressCandidates?Street=202+Birch+Loop&outFields=&outSR=&f=html

Using code from the JS Samples (http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssamples/locator_address.html), I tried to create a web page.  Unfortunately, when I click the button to execute the search and return results to my map, nothing happens. 

If someone could please look at my code and tell me what I'm doing wrong, I'd really, really appreciate it.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>Find Address</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
    <script type="text/javascript">
        dojo.require("esri.map");
        dojo.require("esri.tasks.locator");

        var map, locator;

        function init() {
            
            map = new esri.Map("map", { extent: new esri.geometry.Extent(358704.7747, 5019963.41681, 400356.3737, 5074307.67359, new esri.SpatialReference({ wkid: 26911 }))
            });
            var BoundaryLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://restdata.umatilla.nsn.us/ArcGIS/rest/services/ReservationBoundary/MapServer");
            map.addLayer(BoundaryLayer);

            locator = new esri.tasks.Locator("http://restdata.umatilla.nsn.us/ArcGIS/rest/services/CTUIRAddressLocator/GeocodeServer");
            dojo.connect(locator, "onAddressToLocationsComplete", showResults);
        }

        function locate() {
            map.graphics.clear();
            // this service was published using ArcGIS Server 10, so the following format should work...
            var StreetName = { "SingleLine": "202 Birch Loop" };
            locator.addressToLocations(StreetName);
        }

        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_DIAMOND);
            symbol.setColor(new dojo.Color([255, 0, 0, 0.75]));

            var points = new esri.geometry.Multipoint(map.spatialReference);

            for (var i = 0, il = candidates.length; i < il; i++) {
                candidate = candidates[i];
                if (candidate.score > 70) {
                    var attributes = { address: candidate.StreetName, score: candidate.score, locatorName: candidate.attributes.StreetName };
                    var graphic = new esri.Graphic(candidate.location, symbol, attributes, infoTemplate);
                    map.graphics.add(graphic);
                    map.graphics.add(new esri.Graphic(candidate.location, new esri.symbol.TextSymbol(attributes.address).setOffset(0, 8)));
                    points.addPoint(candidate.location);
                }
            }
            map.setExtent(points.getExtent().expand(3));
        }

        dojo.addOnLoad(init);
    </script>
  </head>
  <body class="tundra">
    Address : <input type="text" id="address" size="60" value="202 Birch Loop" /> 
    <input type="button" value="Locate" onclick="locate()" /><br /><label id="label1" title="asdf" />
    <br />
    <div id="map" style="width:1200px; height:600px; border:1px solid #000;"></div>
  </body>
</html> 



Thank you very, very much in advance for your time and expertise!

Outcomes