Advertisement
Guest User

Untitled

a guest
Aug 4th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.70 KB | None | 0 0
  1. import dispatch._, Defaults._
  2. import scala.concurrent.Await
  3. import scala.concurrent.duration._
  4.  
  5. object Main extends App {
  6.  
  7.   val h = host("maps.googleapis.com")
  8.   val req = h / "maps" / "api" / "distancematrix" / "xml"
  9.   def params(origins: String, destinations: String) =
  10.     req <<? Map("origins" -> origins,
  11.       "destinations" -> destinations,
  12.       "language" -> "pl")
  13.  
  14.   def distanceMatrix(origins: String, destinations: String): xml.Elem = {
  15.     val http = new Http
  16.     val futureDM: Future[xml.Elem] = http(params(origins, destinations) OK as.xml.Elem)
  17.     val dm = Await.result(futureDM, 5.seconds)
  18.     http.shutdown()
  19.     dm
  20.   }
  21.  
  22.   println(distanceMatrix("Berlin", "London"))
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement