android - Geocoder.getFromLocationName()在ICS设备中不起作用

nar*_*esh 11 android geocoding android-maps

我有两个设备.一个是HTC WildFire S,另一个是HTC 1V.我Geocoder.getFromLocationName()在我的应用程序中使用了它.它在HTC野火S中成功运行.但在HTC 1V我得到以下错误.为什么会来?我怎么解决这个问题?请任何人帮助我.

Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); 
//s is the address
List<Address> addresses = geoCoder.getFromLocationName(s, 5); //Here i got the following Exception.
Run Code Online (Sandbox Code Playgroud)

错误

06-18 16:28:17.933: W/System.err(4960): java.io.IOException: Service not Available
06-18 16:28:17.953: W/System.err(4960):at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
Run Code Online (Sandbox Code Playgroud)

位置标签

在此输入图像描述

Ara*_*rim 5

终于我找到了答案:https : //code.google.com/p/android/issues/detail? id =38009

重新启动设备,以使Geocoder正常工作。希望对别人有帮助

注意:有人说如果您使用Google API 16就能使用


小智 -2

  GeoPoint point = new GeoPoint(
                        (int) (LATITUDE * 1E6),
                        (int) (LONGITUDE * 1E6));

String n;

public void someRandomMethod() {
        n = convertPointToLocation(point);
}



public String convertPointToLocation(GeoPoint point) {
        String address = "";
        Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocation(
                    point.getLatitudeE6()  / 1E6,
                    point.getLongitudeE6() / 1E6, 1);

            if (addresses.size() > 0) {
                for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
                    address += addresses.get(0).getAddressLine(index) + " ";
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        return address;
    }
Run Code Online (Sandbox Code Playgroud)