Monday, January 24, 2011

Quick Groovy Script! Google Geocoding!

Nice little script for parsing the Google Ceocoding Web Service. (Groovy 1.7.5)


/**
Simple Script to parse the google geocode web service
http://code.google.com/apis/maps/documentation/geocoding/
*/
def url = new URL('http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true')
def geoCodeResult = new XmlParser().parseText(url.getText())
def lat = geoCodeResult.result.geometry.location.lat.text()
def lng = geoCodeResult.result.geometry.location.lng.text()
println lat
println lng


Outputs :
37.4216227
-122.0840263

2 comments:

  1. I used this geocoding in one of my personal projects

    ReplyDelete
  2. Hey, thanks for this post! Just a question, does this pose any issues regarding the synchronous/asynchronous issue like javascript does?

    ReplyDelete