I am making map app(Android) and i need to make on-click markers with street address in info. After few bad attempts i saw that Geocoder /get from location doesn't work anymore(returns an empty array with null pointer). I found out here LINK that i can do a HTTP/S request to google and i will get back JSON/XML. My question is: how to make the HTTP request(example) when HTTP client is depricated? Can you give me an example of code to send the request and work out the response in JSON(or at least sending only)?
EDIT: I am getting this:android.os.NetworkOnMainThreadException
try {
URL url = new URL(baseUri+builder.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect(); \\exception originated here
is = conn.getInputStream();
reader = new BufferedReader(new InputStreamReader(is));
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
jsonresponse = new JSONArray(builder.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}