Last active
September 26, 2016 13:33
-
-
Save abcdw/64cab0b4645b6101ea5dc9b9b585d5c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; clojure google maps api example | |
(def api-url "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=") | |
(def places | |
[{:descr "Place in Champniers" | |
:lat 45.700160 | |
:lng 0.189237} | |
{:descr "Place in Innopolis" | |
:lat 55.752803 | |
:lng 48.743634} | |
{:descr "Place in Vvedenskaya Sloboda" | |
:lat 55.757499 | |
:lng 48.691750}]) | |
(defn v-contains? [coll val] | |
(some #(= val %) coll)) | |
(defn get-town [data] | |
(as-> data d | |
(:results d) | |
(get d 1) | |
(:address_components d) | |
(filter #(v-contains? (:types %) "locality") d) | |
(first d) | |
(:long_name d))) | |
(defn req-place [point] | |
(let [{:keys [lat lng]} point | |
req-url (str api-url lat "," lng) | |
resp (slurp req-url)] | |
(-> resp | |
(cc/parse-string true) | |
get-town))) | |
(do | |
(println | |
"======================================================\n") | |
(-> (req-place (places 2)) | |
(clojure.pprint/pprint))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment