java - Play Framework 2.x: How do i make a HTTP-GET for an reverse lookup (nominatim OSM)? -
i make simple http playframework (java) doesn't work. i've googled lot read in documentation of play 2.x nothing helped me. examples in documentation did not help.
i write method calls reverse geoconding service (for example this) , gives json data back. need response data jsonnode or that.
i tried following piece of code play homepage should give name of road, did not work.
public static promise<result> reverselookup() {//string lat, string lon final promise<result> resultpromise = ws.url("http://nominatim.openstreetmap.org/reverse?format=json&lat=51.510809&lon=-0.092875").get().map( new function<ws.response, result>() { public result apply(ws.response response) { return ok("road:" + response.asjson().findpath("road")); } } ); return resultpromise; }
i got error here:
[runtimeexception: com.fasterxml.jackson.core.jsonparseexception: unexpected character ('<' (code 60)): expected valid value (number, string, array, object, 'true', 'false' or 'null') @ [source: org.jboss.netty.buffer.channelbufferinputstream@6a43dbaf; line: 1, column: 2]]
there isn't character "<" in json data if this url called manually in browser.
please me. don't it.
edit 10:25 pm:
i tried response.getbody()
output same.
i don't understand error be... here more code:
routes:
post /other/function controllers.mycontroller.anotherfunction()
mycontroller:
private static string reverselookupdata; @bodyparser.of(play.mvc.bodyparser.json.class) public static result anotherfunction() { // gps coordinates passed method (this works point) reverselookup(string lat, string lon); // reverse lookup starts system.out.println("response 1: " + reverselookupdata); system.out.println("response 2: " + reverselookup().tostring()); // code ... } public static promise<string> reverselookup(string lat, string lon) { final promise<string> resultpromise = ws.url("http://nominatim.openstreetmap.org/reverse?format=json&lat="+ lat +"&lon=" + lon).get().map( new function<ws.response, string>() { public string apply(ws.response response) { reverselookupdata = response.getbody(); return "data:" + reverselookupdata; } } ); return resultpromise; }
if run code output command-line window is: response 1: null response 2: play.libs.f$promise@51ebebed
edit
(...) public string apply(ws.response response) { system.out.println("body: " + response.getbody()); return ""; } (...)
now got error message here:
body: <?xml version="1.0" encoding="utf-8" ?> <reversegeocode timestamp='sun, 06 apr 14 21:31:45 +0000' attribution='data ┬® openstreetmap contributors, odbl 1.0. http://www.openstreetmap.org/copyright' querystring=''> <error>unable geocode</error></reversegeocode>
anybody idea why appears or error be? said, when put geocoding address in browser, correct answer.
i tried googles reverse geocoding not work
url:
"http://maps.googleapis.com/maps/api/geocode/json?latlng=51.510809,-0.092875&sensor=false&key={myserverkey}", "http://maps.googleapis.com/maps/api/geocode/json?latlng=51.510809,-0.092875&sensor=false"
sensor true or false, nothing works:
body: { "error_message" : "the 'sensor' parameter specified in request must set either 'true' or 'false'.", "results" : [], "status" : "request_denied" }
i'm grateful :)
ws.url("http://nominatim.openstreetmap.org/reverse") .withqueryparameter("format", "json") .withqueryparameter("lat", lat) .withqueryparameter("lon", lon)
Comments
Post a Comment