Skip to content

Instantly share code, notes, and snippets.

@abcdw
Last active September 26, 2016 13:33
Show Gist options
  • Save abcdw/64cab0b4645b6101ea5dc9b9b585d5c6 to your computer and use it in GitHub Desktop.
Save abcdw/64cab0b4645b6101ea5dc9b9b585d5c6 to your computer and use it in GitHub Desktop.
;; 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