Google AJAX API and pulling in IP county and state

by 5 replies
7
Was wondering anyone had success pulling in the state of the person hitting a web page using (google.loader.ClientLocation.address.region) and getting the state name not abbreviated?

I get HI, but want Hawaii.

Can it be done?

Thanks

Ernie
#programming #ajax #api #county #google #pulling #state
  • Region is universally coded as the two character abbreviation, even in non-Google databases like this one: http://www.maxmind.com/download/geoi...iteCity.dat.gz.

    The best you can do is take the region value and compare it against an array of state names, where the 2 character region is the key, and use the returned value.

    Code:
           = array
          (
          'AL'=>"Alabama",  
          'AK'=>"Alaska",  
          'AZ'=>"Arizona",  
          'AR'=>"Arkansas",  
          'CA'=>"California",  
          'CO'=>"Colorado",  
          'CT'=>"Connecticut",  
          'DE'=>"Delaware",  
          'DC'=>"District Of Columbia",  
          'FL'=>"Florida",  
          'GA'=>"Georgia",  
          'HI'=>"Hawaii",  
          'ID'=>"Idaho",  
          'IL'=>"Illinois",  
          'IN'=>"Indiana",  
          'IA'=>"Iowa",  
          'KS'=>"Kansas",  
          'KY'=>"Kentucky",  
          'LA'=>"Louisiana",  
          'ME'=>"Maine",  
          'MD'=>"Maryland",  
          'MA'=>"Massachusetts",  
          'MI'=>"Michigan",  
          'MN'=>"Minnesota",  
          'MS'=>"Mississippi",  
          'MO'=>"Missouri",  
          'MT'=>"Montana",
          'NE'=>"Nebraska",
          'NV'=>"Nevada",
          'NH'=>"New Hampshire",
          'NJ'=>"New Jersey",
          'NM'=>"New Mexico",
          'NY'=>"New York",
          'NC'=>"North Carolina",
          'ND'=>"North Dakota",
          'OH'=>"Ohio",  
          'OK'=>"Oklahoma",  
          'OR'=>"Oregon",  
          'PA'=>"Pennsylvania",  
          'RI'=>"Rhode Island",  
          'SC'=>"South Carolina",  
          'SD'=>"South Dakota",
          'TN'=>"Tennessee",  
          'TX'=>"Texas",  
          'UT'=>"Utah",  
          'VT'=>"Vermont",  
          'VA'=>"Virginia",  
          'WA'=>"Washington",  
          'WV'=>"West Virginia",  
          'WI'=>"Wisconsin",  
          'WY'=>"Wyoming"
       );
    Code:
     
    • [1] reply
    • Thanks!

      Now I just need to figure out how to insert this array in my javasacript. :-)

      Ernie
      • [2] replies

Next Topics on Trending Feed