AnsweredAssumed Answered

Locator - input address, append my state if the user doesn't enter one?

Question asked by schlot on Dec 3, 2012
Latest reply on Dec 5, 2012 by schlot
I am using the single line World Locator.  I like that it works for both either a full address (310 W High St, Jefferson City, MO 65101) or just a city name (Jefferson City, MO).  Since I am working with data specific to Missouri, I've been asked to make this more user friendly and somehow programmatically manage adding MO at the end of a city name if the user doesn't specify.

I didn't think this would be a problem.  I have an inputText field, textAddress and I'm defining the input address as the value in it.
    var inputAddress = {         "SingleLine" : dojo.byId("txtAddress").value };


In Firebug, it says inputAddress is [object Object], but I can examine the value of SingleLine and see what I entered.

Next I check to see if inputAddress already has the Missouri prefix, MO, at the end of the string:
var checkMO = inputAddress.SingleLine.slice(-2).toUpperCase();  if ( checkMO !== 'MO' ) {                 console.log("not MO");                 inputAddress = inputAddress.SingleLine + ", MO";                 console.log(inputAddress);             }else {                 console.log(inputAddress.SingleLine + " has MO");                            }

Then I pass inputAddress to the locator:
locator.outSpatialReference = map.spatialReference; var options = {     address : inputAddress,     outFields : ["*"]     };     locator.addressToLocations(inputAddress); }


This doesn't work.  I think it is because inputAddress starts out as an object and I'm trying to deal with a string.  I tried  inputAddress + ", MO" instead of inputAddress.SingleLine + ", MO", but neither seems to work.  Instead the locator says it found no matches.  I can see that the inputAddress looks OK in the console window. 

Could someone explain what's wrong with my logic and/or provide a workaround to this?

Outcomes