11

我有两个设备。一种是HTC WildFire S,另一种是HTC 1V。我Geocoder.getFromLocationName()在我的应用程序中使用了。它在HTC wildfire 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.

错误

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)

位置选项卡

在此处输入图像描述

4

2 回答 2

6

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

重新启动您的设备以使 Geocoder 工作。希望它可以帮助某人

注意:有人说如果您使用 Google API 16 它将起作用

于 2013-03-29T22:35:37.303 回答
-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;
    }
于 2013-03-28T23:35:29.370 回答