   (:import [polyline PolylineDecoder]
            [polyline Location]))
 
-(defn polyline []
+(defn polyline [src dst]
   (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"
+                                {:query-params {:origin src
+                                                :destination dst
                                                 :sensor false}}))]
     (-> (parse-string body true) :routes first :overview_polyline :points)))
 

        lon1 (:long a)
        lat2 (:lat b)
        lon2 (:long b)
        R 6372800
        dlat (Math/toRadians (- lat2 lat1))
        dlon (Math/toRadians (- lon2 lon1))
        lat1 (Math/toRadians lat1)

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

