2

私のコード:

                 try
                {

                            Geocoder geocoder;
                        List<Address> addresses;

            geocoder = new Geocoder(LocationActivity.this, Locale.getDefault());

            addresses = geocoder.getFromLocation(longitude,latitude,1);

            Toast.makeText(LocationActivity.this, addresses.size() + "", Toast.LENGTH_LONG).show();

            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(0);
            String country = addresses.get(0).getAddressLine(0);

            Toast.makeText(LocationActivity.this, address + "  " + city + " " + country, Toast.LENGTH_LONG).show();

        }
        catch(Exception e)
        {
            Toast.makeText(LocationActivity.this,e.toString(), Toast.LENGTH_LONG).show();
        }

これは、経度と緯度から住所を取得するための私のコードです。ただし、addresses.sizeが0を返すたびに

誰かがこれのために私を助けることができます

4

5 に答える 5

0

プラットフォームにバックエンド サービスがない場合、Geocoder クエリ メソッドは空のリストを返します。

参照 - http://developer.android.com/reference/android/location/Geocoder.html

于 2014-09-28T05:20:32.517 に答える
0

エミュレーターを使用している場合は、DDMS に移動すると、エミュレーター コントロールが見つかり、その中で有効な緯度経度を指定して [送信] を押します。バッターは、マニフェストにインターネット アクセス許可が記載されていることを確認してください。

    try {
        Geocoder geocoder;
        List<Address> addresses;

        geocoder = new Geocoder(this, Locale.getDefault());

        double longitude = 23.00000;
        double latitude = 72.00000;
        addresses = geocoder.getFromLocation(longitude, latitude, 1);

        Toast.makeText(this, addresses.size() + "", Toast.LENGTH_LONG)
                .show();

        String address = addresses.get(0).getAddressLine(0);
        String city = addresses.get(0).getAddressLine(1);
        String country = addresses.get(0).getAddressLine(2);

        if(address==null)
        address="";
        if(city==null)
            city="";
        if(country==null)
            country="";

        Toast.makeText(this, address + "  " + city + " " + country,
                Toast.LENGTH_LONG).show();

    } catch (Exception e) {
        Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
    }
于 2012-10-08T09:03:02.177 に答える
0

これが役立つかどうかはわかりませんが、IOException が発生していると思います。LogCat を見てください。こちらもご覧ください

于 2012-10-08T09:45:15.383 に答える