Skip to content

Instantly share code, notes, and snippets.

@tbje
Created July 5, 2010 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbje/464177 to your computer and use it in GitHub Desktop.
Save tbje/464177 to your computer and use it in GitHub Desktop.
import scala.xml._
def googleLocalisation(adr: String) : Option[(Double, Double)] = {
val url = "http://maps.google.com/maps/api/geocode/xml?sensor=false&address="
val xml = XML.load(url+adr)
if ((xml \ "status" text) == "OK") {
val lat = ((xml \ "result" \ "geometry" \ "location" \ "lat") text).toDouble
val lng = ((xml \ "result" \ "geometry" \ "location" \ "lng") text).toDouble
Some((lat, lng))
} else {
error("Google request failed: " + xml)
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment