Error handling with addressToLocations

Discussion created by pdprog on Feb 6, 2013
Latest reply on Sep 9, 2013 by JGravois-esristaff
I'm using locator.addressToLocations to geocode an intersection name. My code is working great provided that the intersection name is valid and exists. However, if the address in invalid, the locator simply strips the address and geocodes the city and state. I'd like to catch these cases and handle them myself. (i.e. "Broadway & NoName St, Denver, CO could not be found") I can certainly identify cases where the address is empty in the candidate, but I can't find any reference to the original address I was trying to geocode while I'm in the showResults() function.


relevant snippet:

function showAddress(aAddress, aWeight, aText) {
    lLocator.outSpatialReference = lMap.spatialReference;
    var options = {
        address:{ "SingleLine":aAddress },

function showResults(candidates) {
    try {
        var candidate;
        dojo.every(candidates, function (candidate) {
            console.log(candidate.score + "|" + candidate.attributes.Match_addr);

            // Right here, I'd like to say, if (candidate.address == ""){alert("Bad address: " + candidate.attributes.Request_Address);}
            // But Request_Address isn't something that exists.  How do I get it?
            if (candidate.score > 80) {

function initMap() {
    lMap = new esri.Map("MyMapDiv", {
        basemap:"streets", center:[-93.5, 41.431], zoom:5

    lLocator = new esri.tasks.Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
    dojo.connect(lLocator, "onAddressToLocationsComplete", showResults);
    showAddress( "Broadway & NoName St, Denver, CO", 30, "This is the spot" );