Created
September 26, 2014 06:11
-
-
Save JimmyHoffa/b2f7e4544ab39c37ecd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def getZipLookupUri zip callbackFuncName (+ 'http://api.geonames.org/postalCodeLookupJSON?postalcode=' zip '&country=US&callback=' callbackFuncName '&username=jimmyhoffa')) | |
(def makeSimpleJsonpGetRequest uri | |
(do (= xhr (new XMLHttpRequest())) | |
(xhr.open 'GET' uri true) | |
(= xhr.onload (fn result (eval result.target.response))) | |
(xhr.send))) | |
(def createGeoNameResponseHandler callbackFunc | |
(do | |
(= window.getLatLonFromResponse | |
(fn geoResponse | |
(callbackFunc ((fn (lat: #0.lat lon: #0.lng)) (geoResponse.postalcodes.pop))))) | |
'getLatLonFromResponse')) | |
(def displayLatLon latLonObj ((jQuery '#latlon').text (+ latLonObj.lat ',' latLonObj.lon))) | |
(makeSimpleJsonpGetRequest (getZipLookupUri '80031' (createGeoNameResponseHandler displayLatLon))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment