0

したがって、Reverse GeoCoding を使用しています。すべて正常に動作しますが、StringBuilder にパッケージ化された xml 形式で応答を受け取ります。

たとえば、1行だけを取得しようとしています。: item1 を String で取得したいのですが、どうすればこれを実現できますか?

これが私のコードです。

 public void getPlaces() {

HttpURLConnection connection = null;
URL serverAddress = null;
Double latitude = 37.422006;
Double longitude = -122.084095;

try {
    // build the URL using the latitude & longitude you want to lookup
    // NOTE: I chose XML return format here but you can choose something else
    serverAddress = new URL("http://maps.google.com/maps/geo?q=" + Double.toString(latitude) + "," + Double.toString(longitude) +
                "&output=xml&oe=utf8&sensor=true");
    //set up out communications stuff
    connection = null;

    //Set up the initial connection
    connection = (HttpURLConnection)serverAddress.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    connection.setReadTimeout(10000);

    connection.connect();

    BufferedReader rd  = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String line = null;

    while ((line = rd.readLine()) != null)
    {
        sb.append(line + '\n');
    }
    // now the response is packaged in a string,
    // parse the XML or whatever you need
    String responseText = sb.toString();
    Toast.makeText(this, responseText, Toast.LENGTH_LONG).show();
} catch (Exception ex) {
    ex.printStackTrace();
}



}

ありがとう 。

編集:このリンクを使用して解決:

http://www.smnirven.com/blog/2009/10/09/reverse-geocode-lookup-using-google-maps-api-on-android-revisited/

4

1 に答える 1

0

Geocoderを使用して場所を取得できます

Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
addresses = geocoder.getFromLocation(lattitude,longitude, 1);
于 2012-11-26T12:34:31.097 に答える