                 (Math/cos lat1) (Math/cos lat2)))]
     (* radius-of-earth 2 (Math/asin (Math/sqrt a)))))
 
-(defn interpolate-coordinates [a b c d]
+(defn interpolate-coordinates [a b whole piece]
   (let [lat1 (:lat a)
         lon1 (:long a)
         lat2 (:lat b)

       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))


        lat-diff (- lat2 lat1)
        lon-diff (- lon2 lon1)
        theta (Math/atan (/ lon-diff lat-diff))
        x1 (* (Math/cos theta) piece)
        y1 (* (Math/sin theta) piece)
        x2 (* (Math/cos theta) whole)
        y2 (* (Math/sin theta) whole)
        x-ratio (* (/ x1 x2) lat-diff)
        y-ratio (* (/ y1 y2) lon-diff)]
    {:lat (+ lat1 x-ratio) :long (+ lon1 y-ratio)}))
