I have been reading posts and posts learning jQuery and GoogleMaps API
to develop ubidnship.com (hopefully going live in the next few days
but right now redirects to my company's website, which I don't know if
that's good practice or not!). Now, I am finally brave enough to
share some code with everyone that I think may be helpful.
I have been searching for a way solve the state abbreviations issue
because i have filters that require two letter state codes. Here is
my attempt at a solution that I would like to share with everyone.
I AM ASSUMING ANYONE OUT THERE READING THIS HAS WORKED WITH GEOCODING
AND THIS IS MEANT TO BE A SIMPLE COPY AND PASTE TO TWEAK YOUR STATE
VARIABLE!!!
I WOULD LOVE SOME COMMENTS BECAUSE THIS IS NOT PERFORMANCE TESTED,
BENCHMARKED, YADA YADA
// store the state in a variable
_state =
place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
// find out if the returned state value is NOT a two letter
abbreviation
var words = _state.split(/\b[\s,\.-:;]*/);
var word_count = words.length;
// if state value is multiple words
if (word_count>1){
// reinitiate _state variable
_state = "";
for(i=0;i<word_count;i++){
// return only the first letter, upper case
_state = _state + words[i].substring(0,1).toUpperCase();
}
}
// check if a one-word state was returned
if (_state.length>2){
// replace word with two letter abbreviation
// I am using a JSON array that can be found here
// http://blog.sampsonvideos.com/category/programming/javascript/jquery/
// SPECIAL NOTE: I don't know if this is the correct way to access
the JSON array
// it has not given me problems yet because google maps api has not
returned
// a one-word state yet ;)
_state = stateData.label(_state).data;
}
Enjoy!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---