Skip to content

Instantly share code, notes, and snippets.

@kiwiholmberg
Created January 15, 2014 09:42
Show Gist options
  • Save kiwiholmberg/8433478 to your computer and use it in GitHub Desktop.
Save kiwiholmberg/8433478 to your computer and use it in GitHub Desktop.
Make a JSON array of state capitals with coordinates (data from different sources)
<p class="results"></p>
<ol>
<li>
<p>Name: Alabama</p>
<p>Capital Name: Montgomery</p>
<p>Capital Latitude: 32.361538</p>
<p>Capital Longitude: -86.279118</p>
</li>
<li>
<p>Name: Alaska</p>
<p>Capital Name: Juneau</p>
<p>Capital Latitude: 58.301935</p>
<p>Capital Longitude: -134.419740</p>
</li>
<li>
<p>Name: Arizona</p>
<p>Capital Name: Phoenix</p>
<p>Capital Latitude: 33.448457</p>
<p>Capital Longitude: -112.073844</p>
</li>
<li>
<p>Name: Arkansas</p>
<p>Capital Name: Little Rock</p>
<p>Capital Latitude: 34.736009</p>
<p>Capital Longitude: -92.331122</p>
</li>
<li>
<p>Name: California</p>
<p>Capital Name: Sacramento</p>
<p>Capital Latitude: 38.555605</p>
<p>Capital Longitude: -121.468926</p>
</li>
<li>
<p>Name: Colorado</p>
<p>Capital Name: Denver</p>
<p>Capital Latitude: 39.7391667</p>
<p>Capital Longitude: -104.984167</p>
</li>
<li>
<p>Name: Connecticut</p>
<p>Capital Name: Hartford</p>
<p>Capital Latitude: 41.767</p>
<p>Capital Longitude: -72.677</p>
</li>
<li>
<p>Name: Delaware</p>
<p>Capital Name: Dover</p>
<p>Capital Latitude: 39.161921</p>
<p>Capital Longitude: -75.526755</p>
</li>
<li>
<p>Name: Florida</p>
<p>Capital Name: Tallahassee</p>
<p>Capital Latitude: 30.4518</p>
<p>Capital Longitude: -84.27277</p>
</li>
<li>
<p>Name: Georgia</p>
<p>Capital Name: Atlanta</p>
<p>Capital Latitude: 33.76</p>
<p>Capital Longitude: -84.39</p>
</li>
<li>
<p>Name: Hawaii</p>
<p>Capital Name: Honolulu</p>
<p>Capital Latitude: 21.30895</p>
<p>Capital Longitude: -157.826182</p>
</li>
<li>
<p>Name: Idaho</p>
<p>Capital Name: Boise</p>
<p>Capital Latitude: 43.613739</p>
<p>Capital Longitude: -116.237651</p>
</li>
<li>
<p>Name: Illinois</p>
<p>Capital Name: Springfield</p>
<p>Capital Latitude: 39.783250</p>
<p>Capital Longitude: -89.650373</p>
</li>
<li>
<p>Name: Indiana</p>
<p>Capital Name: Indianapolis</p>
<p>Capital Latitude: 39.790942</p>
<p>Capital Longitude: -86.147685</p>
</li>
<li>
<p>Name: Iowa</p>
<p>Capital Name: Des Moines</p>
<p>Capital Latitude: 41.590939</p>
<p>Capital Longitude: -93.620866</p>
</li>
<li>
<p>Name: Kansas</p>
<p>Capital Name: Topeka</p>
<p>Capital Latitude: 39.04</p>
<p>Capital Longitude: -95.69</p>
</li>
<li>
<p>Name: Kentucky</p>
<p>Capital Name: Frankfort</p>
<p>Capital Latitude: 38.197274</p>
<p>Capital Longitude: -84.86311</p>
</li>
<li>
<p>Name: Louisiana</p>
<p>Capital Name: Baton Rouge</p>
<p>Capital Latitude: 30.45809</p>
<p>Capital Longitude: -91.140229</p>
</li>
<li>
<p>Name: Maine</p>
<p>Capital Name: Augusta</p>
<p>Capital Latitude: 44.323535</p>
<p>Capital Longitude: -69.765261</p>
</li>
<li>
<p>Name: Maryland</p>
<p>Capital Name: Annapolis</p>
<p>Capital Latitude: 38.972945</p>
<p>Capital Longitude: -76.501157</p>
</li>
<li>
<p>Name: Massachusetts</p>
<p>Capital Name: Boston</p>
<p>Capital Latitude: 42.2352</p>
<p>Capital Longitude: -71.0275</p>
</li>
<li>
<p>Name: Michigan</p>
<p>Capital Name: Lansing</p>
<p>Capital Latitude: 42.7335</p>
<p>Capital Longitude: -84.5467</p>
</li>
<li>
<p>Name: Minnesota</p>
<p>Capital Name: Saint Paul</p>
<p>Capital Latitude: 44.95</p>
<p>Capital Longitude: -93.094</p>
</li>
<li>
<p>Name: Mississippi</p>
<p>Capital Name: Jackson</p>
<p>Capital Latitude: 32.320</p>
<p>Capital Longitude: -90.207</p>
</li>
<li>
<p>Name: Missouri</p>
<p>Capital Name: Jefferson City</p>
<p>Capital Latitude: 38.572954</p>
<p>Capital Longitude: -92.189283</p>
</li>
<li>
<p>Name: Montana</p>
<p>Capital Name: Helana</p>
<p>Capital Latitude: 46.595805</p>
<p>Capital Longitude: -112.027031</p>
</li>
<li>
<p>Name: Nebraska</p>
<p>Capital Name: Lincoln</p>
<p>Capital Latitude: 40.809868</p>
<p>Capital Longitude: -96.675345</p>
</li>
<li>
<p>Name: Nevada</p>
<p>Capital Name: Carson City</p>
<p>Capital Latitude: 39.160949</p>
<p>Capital Longitude: -119.753877</p>
</li>
<li>
<p>Name: New Hampshire</p>
<p>Capital Name: Concord</p>
<p>Capital Latitude: 43.220093</p>
<p>Capital Longitude: -71.549127</p>
</li>
<li>
<p>Name: New Jersey</p>
<p>Capital Name: Trenton</p>
<p>Capital Latitude: 40.221741</p>
<p>Capital Longitude: -74.756138</p>
</li>
<li>
<p>Name: New Mexico</p>
<p>Capital Name: Santa Fe</p>
<p>Capital Latitude: 35.667231</p>
<p>Capital Longitude: -105.964575</p>
</li>
<li>
<p>Name: New York</p>
<p>Capital Name: Albany</p>
<p>Capital Latitude: 42.659829</p>
<p>Capital Longitude: -73.781339</p>
</li>
<li>
<p>Name: North Carolina</p>
<p>Capital Name: Raleigh</p>
<p>Capital Latitude: 35.771</p>
<p>Capital Longitude: -78.638</p>
</li>
<li>
<p>Name: North Dakota</p>
<p>Capital Name: Bismarck</p>
<p>Capital Latitude: 48.813343</p>
<p>Capital Longitude: -100.779004</p>
</li>
<li>
<p>Name: Ohio</p>
<p>Capital Name: Columbus</p>
<p>Capital Latitude: 39.962245</p>
<p>Capital Longitude: -83.000647</p>
</li>
<li>
<p>Name: Oklahoma</p>
<p>Capital Name: Oklahoma City</p>
<p>Capital Latitude: 35.482309</p>
<p>Capital Longitude: -97.534994</p>
</li>
<li>
<p>Name: Oregon</p>
<p>Capital Name: Salem</p>
<p>Capital Latitude: 44.931109</p>
<p>Capital Longitude: -123.029159</p>
</li>
<li>
<p>Name: Pennsylvania</p>
<p>Capital Name: Harrisburg</p>
<p>Capital Latitude: 40.269789</p>
<p>Capital Longitude: -76.875613</p>
</li>
<li>
<p>Name: Rhode Island</p>
<p>Capital Name: Providence</p>
<p>Capital Latitude: 41.82355</p>
<p>Capital Longitude: -71.422132</p>
</li>
<li>
<p>Name: South Carolina</p>
<p>Capital Name: Columbia</p>
<p>Capital Latitude: 34.000</p>
<p>Capital Longitude: -81.035</p>
</li>
<li>
<p>Name: South Dakota</p>
<p>Capital Name: Pierre</p>
<p>Capital Latitude: 44.367966</p>
<p>Capital Longitude: -100.336378</p>
</li>
<li>
<p>Name: Tennessee</p>
<p>Capital Name: Nashville</p>
<p>Capital Latitude: 36.165</p>
<p>Capital Longitude: -86.784</p>
</li>
<li>
<p>Name: Texas</p>
<p>Capital Name: Austin</p>
<p>Capital Latitude: 30.266667</p>
<p>Capital Longitude: -97.75</p>
</li>
<li>
<p>Name: Utah</p>
<p>Capital Name: Salt Lake City</p>
<p>Capital Latitude: 40.7547</p>
<p>Capital Longitude: -111.892622</p>
</li>
<li>
<p>Name: Vermont</p>
<p>Capital Name: Montpelier</p>
<p>Capital Latitude: 44.26639</p>
<p>Capital Longitude: -72.57194</p>
</li>
<li>
<p>Name: Virginia</p>
<p>Capital Name: Richmond</p>
<p>Capital Latitude: 37.54</p>
<p>Capital Longitude: -77.46</p>
</li>
<li>
<p>Name: Washington</p>
<p>Capital Name: Olympia</p>
<p>Capital Latitude: 47.042418</p>
<p>Capital Longitude: -122.893077</p>
</li>
<li>
<p>Name: West Virginia</p>
<p>Capital Name: Charleston</p>
<p>Capital Latitude: 38.349497</p>
<p>Capital Longitude: -81.633294</p>
</li>
<li>
<p>Name: Wisconsin</p>
<p>Capital Name: Madison</p>
<p>Capital Latitude: 43.074722</p>
<p>Capital Longitude: -89.384444</p>
</li>
<li>
<p>Name: Wyoming</p>
<p>Capital Name: Cheyenne</p>
<p>Capital Latitude: 41.145548</p>
<p>Capital Longitude: -104.802042</p>
</li>
</ol>
<script src="http://code.jquery.com/jquery-2.0.3.js"></script>
<script>
states_hash =
{
'Alabama': 'AL',
'Alaska': 'AK',
'American Samoa': 'AS',
'Arizona': 'AZ',
'Arkansas': 'AR',
'California': 'CA',
'Colorado': 'CO',
'Connecticut': 'CT',
'Delaware': 'DE',
'District Of Columbia': 'DC',
'Federated States Of Micronesia': 'FM',
'Florida': 'FL',
'Georgia': 'GA',
'Guam': 'GU',
'Hawaii': 'HI',
'Idaho': 'ID',
'Illinois': 'IL',
'Indiana': 'IN',
'Iowa': 'IA',
'Kansas': 'KS',
'Kentucky': 'KY',
'Louisiana': 'LA',
'Maine': 'ME',
'Marshall Islands': 'MH',
'Maryland': 'MD',
'Massachusetts': 'MA',
'Michigan': 'MI',
'Minnesota': 'MN',
'Mississippi': 'MS',
'Missouri': 'MO',
'Montana': 'MT',
'Nebraska': 'NE',
'Nevada': 'NV',
'New Hampshire': 'NH',
'New Jersey': 'NJ',
'New Mexico': 'NM',
'New York': 'NY',
'North Carolina': 'NC',
'North Dakota': 'ND',
'Northern Mariana Islands': 'MP',
'Ohio': 'OH',
'Oklahoma': 'OK',
'Oregon': 'OR',
'Palau': 'PW',
'Pennsylvania': 'PA',
'Puerto Rico': 'PR',
'Rhode Island': 'RI',
'South Carolina': 'SC',
'South Dakota': 'SD',
'Tennessee': 'TN',
'Texas': 'TX',
'Utah': 'UT',
'Vermont': 'VT',
'Virgin Islands': 'VI',
'Virginia': 'VA',
'Washington': 'WA',
'West Virginia': 'WV',
'Wisconsin': 'WI',
'Wyoming': 'WY'
}
var results = {}
var ol = $('ol')
var states = ol.find('li')
states.each(function(i,s){
var q = {
'name': $(s).find('p:eq(0)').text().replace('Name: ',''),
'capital': $(s).find('p:eq(1)').text().replace('Capital Name: ',''),
'lat': $(s).find('p:eq(2)').text().replace('Capital Latitude: ',''),
'long': $(s).find('p:eq(3)').text().replace('Capital Longitude: ','')
}
results[ states_hash[q.name] ] = q
})
console.log(results)
console.log(results.length)
$('.results').html( JSON.stringify(results) )
</script>
@kiwiholmberg
Copy link
Author

This is the result:

{
  "AL": {
    "name": "Alabama",
    "capital": "Montgomery",
    "lat": "32.361538",
    "long": "-86.279118"
  },
  "AK": {
    "name": "Alaska",
    "capital": "Juneau",
    "lat": "58.301935",
    "long": "-134.419740"
  },
  "AZ": {
    "name": "Arizona",
    "capital": "Phoenix",
    "lat": "33.448457",
    "long": "-112.073844"
  },
  "AR": {
    "name": "Arkansas",
    "capital": "Little Rock",
    "lat": "34.736009",
    "long": "-92.331122"
  },
  "CA": {
    "name": "California",
    "capital": "Sacramento",
    "lat": "38.555605",
    "long": "-121.468926"
  },
  "CO": {
    "name": "Colorado",
    "capital": "Denver",
    "lat": "39.7391667",
    "long": "-104.984167"
  },
  "CT": {
    "name": "Connecticut",
    "capital": "Hartford",
    "lat": "41.767",
    "long": "-72.677"
  },
  "DE": {
    "name": "Delaware",
    "capital": "Dover",
    "lat": "39.161921",
    "long": "-75.526755"
  },
  "FL": {
    "name": "Florida",
    "capital": "Tallahassee",
    "lat": "30.4518",
    "long": "-84.27277"
  },
  "GA": {
    "name": "Georgia",
    "capital": "Atlanta",
    "lat": "33.76",
    "long": "-84.39"
  },
  "HI": {
    "name": "Hawaii",
    "capital": "Honolulu",
    "lat": "21.30895",
    "long": "-157.826182"
  },
  "ID": {
    "name": "Idaho",
    "capital": "Boise",
    "lat": "43.613739",
    "long": "-116.237651"
  },
  "IL": {
    "name": "Illinois",
    "capital": "Springfield",
    "lat": "39.783250",
    "long": "-89.650373"
  },
  "IN": {
    "name": "Indiana",
    "capital": "Indianapolis",
    "lat": "39.790942",
    "long": "-86.147685"
  },
  "IA": {
    "name": "Iowa",
    "capital": "Des Moines",
    "lat": "41.590939",
    "long": "-93.620866"
  },
  "KS": {
    "name": "Kansas",
    "capital": "Topeka",
    "lat": "39.04",
    "long": "-95.69"
  },
  "KY": {
    "name": "Kentucky",
    "capital": "Frankfort",
    "lat": "38.197274",
    "long": "-84.86311"
  },
  "LA": {
    "name": "Louisiana",
    "capital": "Baton Rouge",
    "lat": "30.45809",
    "long": "-91.140229"
  },
  "ME": {
    "name": "Maine",
    "capital": "Augusta",
    "lat": "44.323535",
    "long": "-69.765261"
  },
  "MD": {
    "name": "Maryland",
    "capital": "Annapolis",
    "lat": "38.972945",
    "long": "-76.501157"
  },
  "MA": {
    "name": "Massachusetts",
    "capital": "Boston",
    "lat": "42.2352",
    "long": "-71.0275"
  },
  "MI": {
    "name": "Michigan",
    "capital": "Lansing",
    "lat": "42.7335",
    "long": "-84.5467"
  },
  "MN": {
    "name": "Minnesota",
    "capital": "Saint Paul",
    "lat": "44.95",
    "long": "-93.094"
  },
  "MS": {
    "name": "Mississippi",
    "capital": "Jackson",
    "lat": "32.320",
    "long": "-90.207"
  },
  "MO": {
    "name": "Missouri",
    "capital": "Jefferson City",
    "lat": "38.572954",
    "long": "-92.189283"
  },
  "MT": {
    "name": "Montana",
    "capital": "Helana",
    "lat": "46.595805",
    "long": "-112.027031"
  },
  "NE": {
    "name": "Nebraska",
    "capital": "Lincoln",
    "lat": "40.809868",
    "long": "-96.675345"
  },
  "NV": {
    "name": "Nevada",
    "capital": "Carson City",
    "lat": "39.160949",
    "long": "-119.753877"
  },
  "NH": {
    "name": "New Hampshire",
    "capital": "Concord",
    "lat": "43.220093",
    "long": "-71.549127"
  },
  "NJ": {
    "name": "New Jersey",
    "capital": "Trenton",
    "lat": "40.221741",
    "long": "-74.756138"
  },
  "NM": {
    "name": "New Mexico",
    "capital": "Santa Fe",
    "lat": "35.667231",
    "long": "-105.964575"
  },
  "NY": {
    "name": "New York",
    "capital": "Albany",
    "lat": "42.659829",
    "long": "-73.781339"
  },
  "NC": {
    "name": "North Carolina",
    "capital": "Raleigh",
    "lat": "35.771",
    "long": "-78.638"
  },
  "ND": {
    "name": "North Dakota",
    "capital": "Bismarck",
    "lat": "48.813343",
    "long": "-100.779004"
  },
  "OH": {
    "name": "Ohio",
    "capital": "Columbus",
    "lat": "39.962245",
    "long": "-83.000647"
  },
  "OK": {
    "name": "Oklahoma",
    "capital": "Oklahoma City",
    "lat": "35.482309",
    "long": "-97.534994"
  },
  "OR": {
    "name": "Oregon",
    "capital": "Salem",
    "lat": "44.931109",
    "long": "-123.029159"
  },
  "PA": {
    "name": "Pennsylvania",
    "capital": "Harrisburg",
    "lat": "40.269789",
    "long": "-76.875613"
  },
  "RI": {
    "name": "Rhode Island",
    "capital": "Providence",
    "lat": "41.82355",
    "long": "-71.422132"
  },
  "SC": {
    "name": "South Carolina",
    "capital": "Columbia",
    "lat": "34.000",
    "long": "-81.035"
  },
  "SD": {
    "name": "South Dakota",
    "capital": "Pierre",
    "lat": "44.367966",
    "long": "-100.336378"
  },
  "TN": {
    "name": "Tennessee",
    "capital": "Nashville",
    "lat": "36.165",
    "long": "-86.784"
  },
  "TX": {
    "name": "Texas",
    "capital": "Austin",
    "lat": "30.266667",
    "long": "-97.75"
  },
  "UT": {
    "name": "Utah",
    "capital": "Salt Lake City",
    "lat": "40.7547",
    "long": "-111.892622"
  },
  "VT": {
    "name": "Vermont",
    "capital": "Montpelier",
    "lat": "44.26639",
    "long": "-72.57194"
  },
  "VA": {
    "name": "Virginia",
    "capital": "Richmond",
    "lat": "37.54",
    "long": "-77.46"
  },
  "WA": {
    "name": "Washington",
    "capital": "Olympia",
    "lat": "47.042418",
    "long": "-122.893077"
  },
  "WV": {
    "name": "West Virginia",
    "capital": "Charleston",
    "lat": "38.349497",
    "long": "-81.633294"
  },
  "WI": {
    "name": "Wisconsin",
    "capital": "Madison",
    "lat": "43.074722",
    "long": "-89.384444"
  },
  "WY": {
    "name": "Wyoming",
    "capital": "Cheyenne",
    "lat": "41.145548",
    "long": "-104.802042"
  }
}
´´´

@michaelneuder
Copy link

thanks, this was useful

@TannerQuigley
Copy link

TannerQuigley commented Nov 14, 2017

Thanks I really needed this. typo in 'Helana' MT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment