psm1988

Need urgent help in JS code for locator..

Discussion created by psm1988 on Jun 25, 2012
Latest reply on Jun 25, 2012 by psm1988
Hello,

i am using this code, which shows me my map layer and other layouts too. But when i click on button nothing happens. I am not getting any error either..

<!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, IE=9" />
    <title>Find Address</title>
    <style type="text/css">
@import "http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/dojo/dijit/themes/tundra/tundra.css";
</style>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.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(72.711194, 18.901901, 73.223254, 19.316618, new esri.SpatialReference({wkid:4326})) });
          
        var DynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gise-lab-int1:8399/arcgis/rest/services/Test3/MapServer");
        map.addLayer(DynamicMapServiceLayer);

        locator = new esri.tasks.Locator("http://gise-lab-int1:8399/arcgis/rest/services/BusStops1/GeocodeServer");
        dojo.connect(locator, "onAddressToLocationsComplete", showResults);
    }

      function locate() {
        map.graphics.clear();
        var address = {"SingleLine":dojo.byId("address").value};
  var options = {
          address:address,
          searchExtent: map.extent
        }
 
  locator.outSpatialReference= map.spatialReference;
        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 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.address, score: candidate.score};

            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="Backbay Depot, Hiranandani Estate (Thane)" /> <i>(Point1, Point2)</i>

    <input type="button" value="Locate" onclick="locate()" /><br />

    <br />

    <div id="map" style="width:800px; height:600px; border:1px solid #000;"></div>

  </body>

</html>

I am using ArcGIS Server 10. To see where i am getting problem i was using alert() and i found that it doesnt go in loop. Please i need to solve it in 2-3 days only.

please help me fast..

Pratik M

Outcomes