Depois de eu enviar o request ele devolve uma resposta JSON. O que eu queria saber é como recebo essa resposta no meu código e trabalho nela. Estou a trabalhar com java + seam.
importjava.net.HttpURLConnection;importjava.net.URL;importjava.net.URLEncoder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.xpath.XPath;importjavax.xml.xpath.XPathConstants;importjavax.xml.xpath.XPathFactory;importorg.w3c.dom.Document;importorg.w3c.dom.Node;importorg.w3c.dom.NodeList;importorg.xml.sax.InputSource;importjava.io.IOException;importjavax.xml.parsers.ParserConfigurationException;importjavax.xml.xpath.XPathExpressionException;importorg.xml.sax.SAXException;publicclassGeocodingSample{// URL prefix to the geocoderprivatestaticfinalStringGEOCODER_REQUEST_PREFIX_FOR_XML="http://maps.google.com/maps/api/geocode/xml";publicstaticfinalvoidmain(String[]argv)throwsIOException,XPathExpressionException,ParserConfigurationException,SAXException{// query addressStringaddress="1600 Amphitheatre Parkway, Mountain View, CA";// prepare a URL to the geocoderURLurl=newURL(GEOCODER_REQUEST_PREFIX_FOR_XML+"?address="+URLEncoder.encode(address,"UTF-8")+"&sensor=false");// prepare an HTTP connection to the geocoderHttpURLConnectionconn=(HttpURLConnection)url.openConnection();DocumentgeocoderResultDocument=null;try{// open the connection and get results as InputSource.conn.connect();InputSourcegeocoderResultInputSource=newInputSource(conn.getInputStream());// read result and parse into XML DocumentgeocoderResultDocument=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(geocoderResultInputSource);}finally{conn.disconnect();}// prepare XPathXPathxpath=XPathFactory.newInstance().newXPath();// extract the resultNodeListresultNodeList=null;// a) obtain the formatted_address field for every resultresultNodeList=(NodeList)xpath.evaluate("/GeocodeResponse/result/formatted_address",geocoderResultDocument,XPathConstants.NODESET);for(inti=0;i<resultNodeList.getLength();++i){System.out.println(resultNodeList.item(i).getTextContent());}// b) extract the locality for the first resultresultNodeList=(NodeList)xpath.evaluate("/GeocodeResponse/result[1]/address_component[type/text()='locality']/long_name",geocoderResultDocument,XPathConstants.NODESET);for(inti=0;i<resultNodeList.getLength();++i){System.out.println(resultNodeList.item(i).getTextContent());}// c) extract the coordinates of the first resultresultNodeList=(NodeList)xpath.evaluate("/GeocodeResponse/result[1]/geometry/location/*",geocoderResultDocument,XPathConstants.NODESET);floatlat=Float.NaN;floatlng=Float.NaN;for(inti=0;i<resultNodeList.getLength();++i){Nodenode=resultNodeList.item(i);if("lat".equals(node.getNodeName()))lat=Float.parseFloat(node.getTextContent());if("lng".equals(node.getNodeName()))lng=Float.parseFloat(node.getTextContent());}System.out.println("lat/lng="+lat+","+lng);// c) extract the coordinates of the first resultresultNodeList=(NodeList)xpath.evaluate("/GeocodeResponse/result[1]/address_component[type/text() = 'administrative_area_level_1']/country[short_name/text() = 'US']/*",geocoderResultDocument,XPathConstants.NODESET);floatlat=Float.NaN;floatlng=Float.NaN;for(inti=0;i<resultNodeList.getLength();++i){Nodenode=resultNodeList.item(i);if("lat".equals(node.getNodeName()))lat=Float.parseFloat(node.getTextContent());if("lng".equals(node.getNodeName()))lng=Float.parseFloat(node.getTextContent());}System.out.println("lat/lng="+lat+","+lng);}}