Select to view content in your preferred language

Address Locator - what am I doing wrong?

2234
12
10-12-2011 06:55 AM
MatthewGerbrandt
Emerging Contributor
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/findAddressCa...

Using code from the JS Samples (http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssa...), 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;
                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!
0 Kudos
12 Replies
derekswingley1
Deactivated User
If ESRI really wants to help guys that post the problems and seek help,  should tackle the issue (such as var Street = { "Single Line Input": dojo.byId("address").value};  -why it doesn't work).


I'm not sure I understand. Isn't my second post in this thread outlining the specific problem and describing how to fix it? Using anything other than "Street" for the address property name will not work because the locator expects a parameter named "Street".

Maybe gis_tech could provide some feedback on the answers provided in this thread?
0 Kudos
MatthewGerbrandt
Emerging Contributor
swingley - Thank you very much for your reply - you've solved my problem!
0 Kudos
derekswingley1
Deactivated User
Glad to help!
0 Kudos