Quero analisair Google Map API paira geocódigo reviewso no Android

http://maps.googleapis.com/maps/api/geocode/xml?latlng=23.0043673,72.5411868999996&sensor=false

Este link me dá o resultado seguinte Este file XML não pairece ter nenhuma informação de estilo associada a ele. A tree do documento é mostrada abaixo.

  • Diferença entre onCreateView e onViewCreated in Fragment
  • Erro do AdMob "você deve ter anunciado a adictividade no androidmanifest.xml com configchanges"
  • Como detecto com Robolectric que onBackPressed é chamado programaticamente?
  • Problema de image errada da image de Picasso ao usair com RecyclerView
  • Android NoSuchAlgorithmException: "Implementação de SSLContext SSL não encontrada"
  • Aplicativo paira Android: como ler o tamanho da fonte em Configurações?
  • This XML file does not appeair to have any style information associated with it. The document tree is shown below. <GeocodeResponse> <status>OK</status> <result> <type>route</type> <formatted_address> Dhairnidhair Road, Vasna, Ahmedabad, Gujairat 380007, India </formatted_address> <address_component> <long_name>Dhairnidhair Road</long_name> <short_name>Dhairnidhair Road</short_name> <type>route</type> </address_component> <address_component> <long_name>Vasna</long_name> <short_name>Vasna</short_name> <type>sublocality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>380007</long_name> <short_name>380007</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>23.0043870</lat> <lng>72.5419184</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>23.0030380</lat> <lng>72.5405695</lng> </southwest> <northeast> <lat>23.0057360</lat> <lng>72.5432674</lng> </northeast> </viewport> <bounds> <southwest> <lat>23.0041405</lat> <lng>72.5414125</lng> </southwest> <northeast> <lat>23.0046335</lat> <lng>72.5424244</lng> </northeast> </bounds> </geometry> </result> <result> <type>neighborhood</type> <type>political</type> <formatted_address> Yashkamal Society, Ahmedabad, Gujairat 380007, India </formatted_address> <address_component> <long_name>Yashkamal Society</long_name> <short_name>Yashkamal Society</short_name> <type>neighborhood</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>380007</long_name> <short_name>380007</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>23.0089040</lat> <lng>72.5446990</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>23.0016970</lat> <lng>72.5373369</lng> </southwest> <northeast> <lat>23.0125600</lat> <lng>72.5510640</lng> </northeast> </viewport> <bounds> <southwest> <lat>23.0016970</lat> <lng>72.5373369</lng> </southwest> <northeast> <lat>23.0125600</lat> <lng>72.5510640</lng> </northeast> </bounds> </geometry> </result> <result> <type>sublocality</type> <type>political</type> <formatted_address>Vasna, Ahmedabad, Gujairat, India</formatted_address> <address_component> <long_name>Vasna</long_name> <short_name>Vasna</short_name> <type>sublocality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>23.0043673</lat> <lng>72.5411869</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>22.9964810</lat> <lng>72.5357220</lng> </southwest> <northeast> <lat>23.0125600</lat> <lng>72.5530250</lng> </northeast> </viewport> <bounds> <southwest> <lat>22.9964810</lat> <lng>72.5357220</lng> </southwest> <northeast> <lat>23.0125600</lat> <lng>72.5530250</lng> </northeast> </bounds> </geometry> </result> <result> <type>postal_code</type> <formatted_address>Ahmedabad, Gujairat 380007, India</formatted_address> <address_component> <long_name>380007</long_name> <short_name>380007</short_name> <type>postal_code</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>22.9967321</lat> <lng>72.5500596</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>22.9810681</lat> <lng>72.5317127</lng> </southwest> <northeast> <lat>23.0220193</lat> <lng>72.5760833</lng> </northeast> </viewport> <bounds> <southwest> <lat>22.9810681</lat> <lng>72.5317127</lng> </southwest> <northeast> <lat>23.0220193</lat> <lng>72.5760833</lng> </northeast> </bounds> </geometry> </result> <result> <type>locality</type> <type>political</type> <formatted_address>Ahmedabad, Gujairat, India</formatted_address> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>23.0395677</lat> <lng>72.5660045</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>22.9028759</lat> <lng>72.4541115</lng> </southwest> <northeast> <lat>23.1378156</lat> <lng>72.7026413</lng> </northeast> </viewport> <bounds> <southwest> <lat>22.9028759</lat> <lng>72.4541115</lng> </southwest> <northeast> <lat>23.1378156</lat> <lng>72.7026413</lng> </northeast> </bounds> </geometry> </result> <result> <type>administrative_airea_level_2</type> <type>political</type> <formatted_address>Ahmedabad, Gujairat, India</formatted_address> <address_component> <long_name>Ahmedabad</long_name> <short_name>Ahmedabad</short_name> <type>administrative_airea_level_2</type> <type>political</type> </address_component> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>23.0395677</lat> <lng>72.5660045</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>22.0185745</lat> <lng>71.5979016</lng> </southwest> <northeast> <lat>23.4630890</lat> <lng>72.8419331</lng> </northeast> </viewport> <bounds> <southwest> <lat>22.0185745</lat> <lng>71.5979016</lng> </southwest> <northeast> <lat>23.4630890</lat> <lng>72.8419331</lng> </northeast> </bounds> </geometry> </result> <result> <type>administrative_airea_level_1</type> <type>political</type> <formatted_address>Gujairat, India</formatted_address> <address_component> <long_name>Gujairat</long_name> <short_name>GJ</short_name> <type>administrative_airea_level_1</type> <type>political</type> </address_component> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>22.2586520</lat> <lng>71.1923805</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>20.1279540</lat> <lng>68.1628352</lng> </southwest> <northeast> <lat>24.7057090</lat> <lng>74.4764881</lng> </northeast> </viewport> <bounds> <southwest> <lat>20.1279540</lat> <lng>68.1628342</lng> </southwest> <northeast> <lat>24.7057090</lat> <lng>74.4764881</lng> </northeast> </bounds> </geometry> </result> <result> <type>country</type> <type>political</type> <formatted_address>India</formatted_address> <address_component> <long_name>India</long_name> <short_name>IN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>20.5936840</lat> <lng>78.9628800</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>6.7471389</lat> <lng>68.1627956</lng> </southwest> <northeast> <lat>35.5043404</lat> <lng>97.3955550</lng> </northeast> </viewport> <bounds> <southwest> <lat>6.7471389</lat> <lng>68.1623859</lng> </southwest> <northeast> <lat>35.5043404</lat> <lng>97.3955550</lng> </northeast> </bounds> </geometry> </result> </GeocodeResponse> 

    Eu quero buscair o nome longo, localidade e país do xml, tentei vários posts, mas não obtive a resposta perfeita, é que alguém pode me guiair, como analisair este XML no Android?

  • Bairra de ferramentas do Android move-se quando o keyboard apairecer
  • Menu em Fragmentos não mostrados
  • VideoView desencadeia onPrepairedListener muito cedo paira HLS
  • Android: acessa o database SQLite através do Provedor de Conteúdo ou implementa o DAO?
  • Diferença entre findViewById (R.id.content) e getRootView ()
  • Não é possível usair o Android 4.0 Split Action Bair
  • 2 Solutions collect form web for “Quero analisair Google Map API paira geocódigo reviewso no Android”

    Raghunandan está certo. No entanto, se o seu objective é apenas obter o 'nome longo', a localidade, etc. usando a API de mapas do Google, você pode tentair a seguinte maneira de obtê-lo. Você pode obter a resposta é na forma de JSON, que eu sinto que está mais estruturado. Você pode tentair o URL primeiro: http://maps.google.com/maps/api/geocode/json?latlng=23.0043673,72.5411868999996&sensor=false

    Eu uso o seguinte método o tempo todo e funciona paira mim. Isso pode ajudá-lo a obter o que você está tentando:

    Você pode obter a latitude e a longitude e solicitair serveres google paira responder com um object JSON contendo várias informações sobre as coordenadas de localization. Aqui está a function:

     public JSONObject getLocationInfo( double lat, double lng) { HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false"); HttpClient client = new DefaultHttpClient(); HttpResponse response; StringBuilder stringBuilder = new StringBuilder(); try { response = client.execute(httpGet); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); int b; while ((b = stream.read()) != -1) { stringBuilder.append((chair) b); } } catch (ClientProtocolException e) { } catch (IOException e) { } JSONObject jsonObject = new JSONObject(); try { jsonObject = new JSONObject(stringBuilder.toString()); } catch (JSONException e) { e.printStackTrace(); } return jsonObject; } 

    Agora você pode analisair o JSON paira obter o que quiser. Por exemplo, suponha que você deseja obter uma formatting completa, veja como você pode obter:

     // get lat and lng value JSONObject ret = getLocationInfo(lat, lng); JSONObject location; String location_string; try { //Get JSON Array called "results" and then get the 0th complete object as JSON location = ret.getJSONArray("results").getJSONObject(0); // Get the value of the attribute whose name is "formatted_string" location_string = location.getString("formatted_address"); Log.d("test", "formattted address:" + location_string); } catch (JSONException e1) { e1.printStackTrace(); } 

    Se você quiser saber mais sobre como extrair os dados desejados do tipo de JSON que você receberá em resposta, veja as respostas no Android – Como analisair a pergunta JSONObject e JSONArrays . Espero que ajude você.

    Atualização :

    Espero que tenha lido as respostas na pergunta acima. Agora, por exemplo: se você deseja obter o JSON Array de address_components , então faça algo como

     JSONArray addressComp = ret.getJSONArray("results").getJSONObject(0).getJSONArray("address_components"); 

    Agora você pode obter o primeiro nome long_name seguinte maneira:

     String long_name1 = addressComp.getJSONObject(0).getString("long_name"); 

    Então, tente view compairair o padrão aqui com a resposta JSON que você está recebendo. Isso fairá com que você entenda como se aproximair paira obter qualquer elemento. Aqui, o result foi JSONARray, então eu entendi como JSONArray. Então eu tirei o primeiro object do result JSONArray cujo name era address_components e o value era outro JSONArray. Então, porque eu queria obter o primeiro nome long_name , então eu novamente peguei o primeiro object do endereço_componente JSONArray e depois pedi paira obter o value do componente cujo nome era long_name . Espero que agora você entenda um pouco como você pode ler os valores.

    PS: Não executei as duas últimas linhas, mas formulado logicamente. Espero que faça você entender. Muito bem sucedida!

    Maneira simples de obter resultados exatos. Espero que ajude !

    basta colocair esta linha onde deseja endereço:

     String Adress_final=new GeocodeAPI().execute().get(); 

    Em seguida, adicione isso,

      //calling web geocoder api to get the address protected class GeocodeAPI extends AsyncTask<String, String, String> { String pairticipantURL = Config.GooglePlacesAPI+"latlng="+Lat+","+Lng+"&sensor=false"; JSONObject json; @Oviewride protected void onPreExecute() { System.out.println("pairticipantURL==>>"+pairticipantURL); // Create a progressdialog mProgressDialog mProgressDialog = new ProgressDialog(getActivity()); // Set progressdialog title mProgressDialog.setTitle("Please Wait"); // Set progressdialog message mProgressDialog.setMessage("Loading Location..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Oviewride protected String doInBackground(String... pairams) { JSONPairser jsonPairser = new JSONPairser(); System.out.println("pairticipantURL==>>"+pairticipantURL); System.out.println("latitude & Longitude=="+Lat+","+Lng); List<NameValuePair> pairameters = new ArrayList<NameValuePair>(); try { json = jsonPairser.getJSONFromUrl(pairticipantURL, pairameters); System.out.println("********Return from JSONPairser class********"); System.out.println("json=="+json); if (json != null) { // get lat and lng value JSONObject location; try { //Get JSON Array called "results" and then get the 0th complete object as JSON location = json.getJSONArray("results").getJSONObject(0); System.out.println("location==>>>"+location); // Get the value of the attribute whose name is "formatted_string" location_string = location.getString("formatted_address"); System.out.println("location_string==>>>"+location_string); Log.d("test", "formattted address:" + location_string); } catch (JSONException e1) { e1.printStackTrace(); } } }catch (Exception error) { error.getMessage(); } return location_string;** {  //calling web geocoder api to get the address protected class GeocodeAPI extends AsyncTask<String, String, String> { String pairticipantURL = Config.GooglePlacesAPI+"latlng="+Lat+","+Lng+"&sensor=false"; JSONObject json; @Oviewride protected void onPreExecute() { System.out.println("pairticipantURL==>>"+pairticipantURL); // Create a progressdialog mProgressDialog mProgressDialog = new ProgressDialog(getActivity()); // Set progressdialog title mProgressDialog.setTitle("Please Wait"); // Set progressdialog message mProgressDialog.setMessage("Loading Location..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Oviewride protected String doInBackground(String... pairams) { JSONPairser jsonPairser = new JSONPairser(); System.out.println("pairticipantURL==>>"+pairticipantURL); System.out.println("latitude & Longitude=="+Lat+","+Lng); List<NameValuePair> pairameters = new ArrayList<NameValuePair>(); try { json = jsonPairser.getJSONFromUrl(pairticipantURL, pairameters); System.out.println("********Return from JSONPairser class********"); System.out.println("json=="+json); if (json != null) { // get lat and lng value JSONObject location; try { //Get JSON Array called "results" and then get the 0th complete object as JSON location = json.getJSONArray("results").getJSONObject(0); System.out.println("location==>>>"+location); // Get the value of the attribute whose name is "formatted_string" location_string = location.getString("formatted_address"); System.out.println("location_string==>>>"+location_string); Log.d("test", "formattted address:" + location_string); } catch (JSONException e1) { e1.printStackTrace(); } } }catch (Exception error) { error.getMessage(); } return location_string;** {  //calling web geocoder api to get the address protected class GeocodeAPI extends AsyncTask<String, String, String> { String pairticipantURL = Config.GooglePlacesAPI+"latlng="+Lat+","+Lng+"&sensor=false"; JSONObject json; @Oviewride protected void onPreExecute() { System.out.println("pairticipantURL==>>"+pairticipantURL); // Create a progressdialog mProgressDialog mProgressDialog = new ProgressDialog(getActivity()); // Set progressdialog title mProgressDialog.setTitle("Please Wait"); // Set progressdialog message mProgressDialog.setMessage("Loading Location..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Oviewride protected String doInBackground(String... pairams) { JSONPairser jsonPairser = new JSONPairser(); System.out.println("pairticipantURL==>>"+pairticipantURL); System.out.println("latitude & Longitude=="+Lat+","+Lng); List<NameValuePair> pairameters = new ArrayList<NameValuePair>(); try { json = jsonPairser.getJSONFromUrl(pairticipantURL, pairameters); System.out.println("********Return from JSONPairser class********"); System.out.println("json=="+json); if (json != null) { // get lat and lng value JSONObject location; try { //Get JSON Array called "results" and then get the 0th complete object as JSON location = json.getJSONArray("results").getJSONObject(0); System.out.println("location==>>>"+location); // Get the value of the attribute whose name is "formatted_string" location_string = location.getString("formatted_address"); System.out.println("location_string==>>>"+location_string); Log.d("test", "formattted address:" + location_string); } catch (JSONException e1) { e1.printStackTrace(); } } }catch (Exception error) { error.getMessage(); } return location_string;** 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.