Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using the esri javascript api to make a web map. I need to use an address locator to geocode a point and then depending on where that point lands information populates a side panel. I am assuming you have to pass the coordinates to an identify function but I have no idea how to do this. Basically, I want the person to enter an address, it zooms to the address and information about the area populates the side panel. The information in the side panel would come from attributes from various polygon layers on the map. Any sample codes would be appreciated. Especially how to take the geocoded result and populate a identify function with the coordinates. (Or however this is handled) Thanks

share|improve this question

1 Answer 1

This should get you started:

  var loc = new esri.tasks.Locator("http://...");
  dojo.connect(loc, "onAddressToLocationsComplete", onGeocodeComplete);
  locator.addressToLocations(address,...);

  function onGeocodeComplete(candidates) {
    // You'll want to find the best candidate by looping
    // through all the candidates and not just selecting first
    var geom = candidates[0].location;

    var identify = new esri.tasks.IdentifyTask("http://...")
    var idParams = new esri.tasks.IdentifyParameters();
    // Set your ID parameters here

    identify.execute(idParams, onIdentifyComplete);
  }

  function onIdentifyComplete(idResults) {
    // Add your code here
  }
share|improve this answer
1  
This is the general workflow but leaves out a key detail: set the idParams.geometry property to the geometry from the best location returned by the geocoder. You would also probably want to specify a tolerance. One more thing: I like to be consistent dojo.connect() to add callbacks or by supplying them as arguments to functions. Personally, I prefer the latter. –  Derek Swingley Aug 19 '11 at 15:56
    
@Derek: He'll need to set up the rest of the idParams as well, such as current map extent, etc. As for consistency, I pulled the code from two examples (instead of my head :p). I almost never use dojo.connect, instead I pass the function parameters, but I'd definitely agree with keeping consistent. At least this way he sees both methods :) –  Sasa Ivetic Aug 19 '11 at 15:59
    
So I did as you suggested and tried to set it up using two esri examples, but I am still missing something. This is what I have so far. busstops.provo.org/address.html If I had a working example to see how it is done that would help out so much. Thanks –  Stan McShinsky Aug 22 '11 at 15:08
    
@Stan I see this error coming back from the service when your identify request is sent: "'mapExtent' parameter not specified" Try specifying a mapExtent such as identifyParams.mapExtent = map.extent. I would also zoom to your point before setting up your identify params, not after. –  Derek Swingley Aug 22 '11 at 18:36
    
@Dererk Thanks that did the trick. –  Stan McShinsky Aug 22 '11 at 19:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.