0

Something strange with U.S. Locations

Folks, I am seeing something a bit strange with U.S. Locations.  I want the user to search for a location and select it.. This gives me lat/long that can be used later for routing etc.. 

 

I also want to parse that location so I can have a U.S. Postal Address.   So.. taking just the happy path for now (not worrying about address line 2 just yet)...  I have the following logic... basically .. just split the text of the location into its address parts. 

theCode

 

Since the State and the Zip are in one array element.. I also split that again.   Here in lies the anomaly..   Notice that there appears to be an extra space between state and zip.. (INxx46311).. Ok.. still not a huge problem.. I can say take the first element (0) and make that the state .. and take the last element and make it the zip ..  When I count the stZip array .. it gives me TWO (2)..  when there are actually THREE (3) items.. 

location

 

I can mitigate this issue by parsing the stZip with two spaces... but I am not certain it will always be two spaces.. 

 

Anyone else seeing something strange.. or can offer insights ?? 

4 replies

null
    • Birger_H
    • 4 yrs ago
    • Reported - view

    Counting of array item starts with 0 - so item(Array, 2) is the third element.

    Birger

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Birger, 

    that has not been my experience.   cnt / count returns the number of items... and YES.. in an array the ordinal position starts at 0.

    Here is a snap shot of a three item array.. the count is THREE

    array

     

    Here is a count of another three item array .. where the second item (ordinal postion 1) is empty.  Notice that the count says 2...  In my opinion, it should say three like the prior example. 

    array 2

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, Looks like you found a twofer.

     

    If you are concerned about the extra space being inconsistent, you can test for it with substr(), but I'll bet it's consistent. I don't think it should be there though.

     

    Nice find with the count() function. I agree, it should count, "", as an item.

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Sean.. yeah.. I was thinking a contains(text(foobar), ",,") .. or something like that.. .. Or heck.. maybe even split the split based on "," .. LOL.. 

    While I have NOT tried it.. I suspect the DOWNSIDE of the "Location" object is that the application will have to be connected to the internet when creating / looking it up..  So, odds are.. I will go with simple address lines . .and then use an API to attempt a translation to lat / long as needed. 

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 1353Views