android - Geocoder.getFromLocationName() is not working in ICS device

ε祈祈猫儿з 提交于 2019-12-21 07:38:58

问题


I have two devices. One is HTC WildFire S and other one is HTC 1V. I used the Geocoder.getFromLocationName() in my application. It is running successfully in the HTC wildfire S. But in the HTC 1V i got the following error. why it's came? How can i solve this? please can anybody help me.

Code

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

Error

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)

Location Tab


回答1:


Finally i found the answer :https://code.google.com/p/android/issues/detail?id=38009

Reboot your device for Geocoder to work. Hope it helps someone

Note: some say it will work if you use 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;
    }


来源:https://stackoverflow.com/questions/11098983/android-geocoder-getfromlocationname-is-not-working-in-ics-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!