Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Created March 31, 2013 16:38
Show Gist options
  • Save FranckSilvestre/5281208 to your computer and use it in GitHub Desktop.
Save FranckSilvestre/5281208 to your computer and use it in GitHub Desktop.
OpenStreetMap search with Groovy HTTPBuilder
package osm
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
/**
*
* @author franck Silvestre
*/
class OSMSearchTest extends GroovyTestCase {
void testConnectionXMLOpenStreetMap() {
def status = "success"
def http = new HTTPBuilder("http://nominatim.openstreetmap.org/")
http.request(Method.GET, ContentType.XML) {
uri.path = 'search?q=135+pilkington+avenue,+birmingham&format=xml&polygon=1&addressdetails=1'
response.success = { resp, searchresults -> println ">>>>> ${searchresults.place.country.text()}" }
// handler for any failure status code:
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
status = "failure"
}
}
status
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment