Is there a way to reference the item returned by addressToLocations

827
2
05-18-2010 02:32 AM
JohnMonnett
New Contributor
In the callback from addressToLocations,  there does not seem to be a way to reference the item that you are geocoding.    I would like to give an ID as a parameter that would be returned in the callback so that I know the exact item that the geocoding was performed for.
0 Kudos
2 Replies
JohnMonnett
New Contributor
Here a sample of my code. In the callback, I would like to have the value of currentItem.id at the time the call to "addressToLocations" was made.


address.Address = items.address;
address.City = items.city;
address.State = items.state;
address.Zip = items.zip;
var currentItem = items;
this._locator.addressToLocations(address, ["Loc_name", "StreetName", "City", "State", "ZIP", "Match_addr"] ,
  dojo.hitch(this, function(candidates) {
  var candidate;
        for (var i=0, il=candidates.length; i<il; i++) {
           candidate = candidates;
           if (candidate.score >=  80) {
       this.addDataToMap("0" , currentItem.geoType, currentItem.image, currentItem.name, 
         currentItem.id,
         currentItem.address,
         currentItem.city,
         currentItem.state,
         currentItem.zip, candidate.location.x, candidate.location.y ,null);
          }
      }
}));


0 Kudos
JohnMonnett
New Contributor
After reading up on dojo.hitch in "the Definitive Guide" by Matthew Russell, I learned that one can pass extra parameters using dojo.hitch.  Now I can pass the item index "i" and get it back on the callback "index".

this._locator.addressToLocations(address, ["Loc_name", "StreetName", "City", "State", "ZIP", "Match_addr"] , dojo.hitch(this, function(index,candidates) {
    var candidate;
    for (var i=0, il=candidates.length; i<il; i++) {
             candidate = candidates;
          if (candidate.score >=  80) {
          this.addDataToMap("0" , this._items[index].geoType, this._items[index].image, this._items[index].name, 
          this._items[index].id,
          this._items[index].address,
          this._items[index].city,
          this._items[index].state,
          this._items[index].zip, candidate.location.x, candidate.location.y ,null);
          }
      }
},
i
));
0 Kudos