Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>if someone have same question you can use GoogleGeoCodeResponse provided by romu31 :</p> <pre><code>public class GoogleGeoCodeResponse { public String status; public results[] results; public GoogleGeoCodeResponse() { } public class results { public String formatted_address; public geometry geometry; public String[] types; public address_component[] address_components; } public class geometry { public bounds bounds; public String location_type; public location location; public bounds viewport; } public class bounds { public location northeast; public location southwest; } public class location { public String lat; public String lng; } public class address_component { public String long_name; public String short_name; public String[] types; }} </code></pre> <p>and <a href="https://code.google.com/p/google-gson/" rel="nofollow">Gson</a> <a href="http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html" rel="nofollow">API</a> Ex:</p> <pre><code> Gson gson = new Gson(); GoogleGeoCodeResponse result = gson.fromJson(jsonCoord(URLEncoder.encode(address, "UTF-8")); GoogleGeoCodeResponse.class); double lat = Double.parseDouble(result.results[0].geometry.location.lat); double lng = Double.parseDouble(result.results[0].geometry.location.lng); </code></pre> <p>and this function to get it:</p> <pre><code>private String jsonCoord(String address) throws IOException { URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&amp;sensor=false"); URLConnection connection = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; String jsonResult = ""; while ((inputLine = in.readLine()) != null) { jsonResult += inputLine; } in.close(); return jsonResult; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload