android - Obtaining State abbreviation from getAdminArea(); -
i've attempted 2 different ways in trying obtain city name state abbreviation address class, no luck. first returning state "ca 92055" zip code, , sec effort returns total state name. quick ways around this?
first effort state ends returning "ca 92055" (zip followed after abbrev)
geocoder geocoder = new geocoder(getactivity(), locale.getdefault()); list<address> addresses; seek { addresses = geocoder.getfromlocation(mlatitude, mlongitude, 10); int i=1; for(address addobj:addresses) { // looping 1 time if(i==1) { string add_line1_extract; add_line1_extract=addobj.getaddressline(1); string string = add_line1_extract; string[] parts = string.split(","); //setting city mcity = parts[0]; //setting state mstate = parts[1]; // final output string cityandstate = mcity + ", " + mstate; i++; } } } grab (ioexception e1) { // todo auto-generated grab block e1.printstacktrace(); }
second attempt, getting closer no zip now...but... (returns total state name):
geocoder geocoder = new geocoder(getactivity(), locale.getdefault()); list<address> addresses; seek { addresses = geocoder.getfromlocation(mlatitude, mlongitude, 10); int i=1; for(address addobj:addresses) { // looping 1 time if(i==1) { //setting city mcity = addobj.getsublocality(); //setting state mstate = addobj.getadminarea(); i++; } } } grab (ioexception e1) { // todo auto-generated grab block e1.printstacktrace(); }
i don't believe can state abbreviation straight getadminarea() despite documentation says. however, when dealing , canada, can set hashmap map out state/provinces abbreviations on reference.
use this:
map<string, string> states = new hashmap<string, string>(); states.put("alabama","al"); states.put("alaska","ak"); states.put("alberta","ab"); states.put("american samoa","as"); states.put("arizona","az"); states.put("arkansas","ar"); states.put("armed forces (ae)","ae"); states.put("armed forces americas","aa"); states.put("armed forces pacific","ap"); states.put("british columbia","bc"); states.put("california","ca"); states.put("colorado","co"); states.put("connecticut","ct"); states.put("delaware","de"); states.put("district of columbia","dc"); states.put("florida","fl"); states.put("georgia","ga"); states.put("guam","gu"); states.put("hawaii","hi"); states.put("idaho","id"); states.put("illinois","il"); states.put("indiana","in"); states.put("iowa","ia"); states.put("kansas","ks"); states.put("kentucky","ky"); states.put("louisiana","la"); states.put("maine","me"); states.put("manitoba","mb"); states.put("maryland","md"); states.put("massachusetts","ma"); states.put("michigan","mi"); states.put("minnesota","mn"); states.put("mississippi","ms"); states.put("missouri","mo"); states.put("montana","mt"); states.put("nebraska","ne"); states.put("nevada","nv"); states.put("new brunswick","nb"); states.put("new hampshire","nh"); states.put("new jersey","nj"); states.put("new mexico","nm"); states.put("new york","ny"); states.put("newfoundland","nf"); states.put("north carolina","nc"); states.put("north dakota","nd"); states.put("northwest territories","nt"); states.put("nova scotia","ns"); states.put("nunavut","nu"); states.put("ohio","oh"); states.put("oklahoma","ok"); states.put("ontario","on"); states.put("oregon","or"); states.put("pennsylvania","pa"); states.put("prince edward island","pe"); states.put("puerto rico","pr"); states.put("quebec","pq"); states.put("rhode island","ri"); states.put("saskatchewan","sk"); states.put("south carolina","sc"); states.put("south dakota","sd"); states.put("tennessee","tn"); states.put("texas","tx"); states.put("utah","ut"); states.put("vermont","vt"); states.put("virgin islands","vi"); states.put("virginia","va"); states.put("washington","wa"); states.put("west virginia","wv"); states.put("wisconsin","wi"); states.put("wyoming","wy"); states.put("yukon territory","yt");
android reverse-geocoding
No comments:
Post a Comment