Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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