我在使用Clojure中的Google地图api时收到此错误
(defn calculate-distance-matrix
""
[context]
;(def nearby-search-fucntion (do-nearby-search property-id context place-type) )
(let [r (. (. (. (DistanceMatrixApi/newRequest
context) origins (latlng {:lat 44.7415131 :lng 20.4957884}) )
destinations (latlng {:lat 44.71018809999999 :lng 20.50643759999999})) await)]
{:distance (-> r
.rows
first
.elements
first
.distance
.inMeters)
:duration (-> r
.rows
first
.elements
first
.distance
.inSeconds)})
)
错误讯息:
IllegalArgumentException No matching method found: origins for class com.google.maps.DistanceMatrixApiRequest clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
顺便说一下,这是Latlng功能:
(defn latlng
"Accepts a Latitiude and Longitude Key pairs"
[{:keys [lat lng]}]
(LatLng. lat lng))
答案 0 :(得分:1)
origins
接受Java varargs,它是Clojure的一个数组。所以你需要做的调用可能更像是:
(. (. (. (DistanceMatrixApi/newRequest context) origins (into-array [(latlng {:lat 44.7415131 :lng 20.4957884})]))
其中into-array接受一个集合并根据数组的第一个元素的类型返回一个数组(此处为LatLng)。