         a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2)))
              (* (Math/sin (/ dlon 2)) (Math/sin (/ dlon 2))
                 (Math/cos lat1) (Math/cos lat2)))]
-    (* R 2 (Math/asin (Math/sqrt a)))))
+    (* radius-of-earth 2 (Math/asin (Math/sqrt a)))))
 
 (defn interpolate-coordinates [a b c d]
   (let [lat1 (:lat a)

  (:import [polyline PolylineDecoder]
           [polyline Location]))

(defn polyline []
  (let [body (:body (client/get "http://maps.googleapis.com/maps/api/directions/json"
                                {:query-params {:origin "Intersection of Main Street and Stephenson Street, Duryea, PA"
                                                :destination "Intersection of Main Street and Phoenix Street, Duryea, PA"
                                                :sensor false}}))]
    (-> (parse-string body true) :routes first :overview_polyline :points)))


       n
       (recur tail distance (+ k head) (inc n)))))

(defn target-coordinates [src dst meters-away]
  (let [coordinates (reverse (decode-polyline (polyline src dst)))
        pairs (partition 2 1 coordinates)
        segments (map (fn [[a b]] (haversine a b)) pairs)
        back-segment (take-segments segments meters-away)
        front-segment (dec back-segment)
        front-distance (reduce + (take front-segment segments))
        back-coordinate (nth coordinates back-segment)   
        front-coordinate (nth coordinates front-segment)
        front-to-target (- meters-away front-distance)]
    (interpolate-coordinates front-coordinate back-coordinate front-to-target meters-away)))

(defroutes routes
  (POST "/rush-hour/api/triangulate/edn" {:keys [body]}
        (let [{:keys [src dst]} (read-string (slurp body))]
          (pr-str {:coordinates (interpolate-coordinates)}))))

(def app (wrap-params #'routes))

