安卓 - Geocoder.getFromLocationName() 在ICS设备上无法正常工作

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)

位置选项卡

展示位置选项卡


这只是一个警告,表示地理编码器不可用,您在One V上设置了互联网访问权限吗?地理编码器需要互联网访问权限来检索结果。编辑:您的应用程序在此阶段没有崩溃,对吗? - Donal Rafferty
1
是的,我有互联网权限。 - naresh
是的,但这个设备是否有连接性呢?您在测试时能否在该设备上浏览网页? - Donal Rafferty
设置中的位置服务是否已开启?在SGS II ICS上,它们在这里:设置>位置服务。必须点击其中的选项。 - Donal Rafferty
我添加了位置服务选项卡,请参考一下。 - naresh
2个回答

6

这个错误出现在Google Map API V1中。我已经尝试在Google Map v2上进行了一些语法更改,它可以在所有Android设备上很好地工作。请注意,对于Google Map V2,您不再需要导入Google APIs。 - Araib karim
在我的V2地图应用中它不起作用...你指的是什么类型的导入? - Umberto
最终它仍然无法工作...即使使用API 16。我该如何解决这个问题? - Umberto

-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;
    }

1
请不要仅仅提供代码作为你的答案。为什么这是正确的答案? - Lee Taylor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接