Android 地理编码器在模拟器上工作吗

Android 地理编码器在模拟器上工作吗,android,android-emulator,emulation,android-location,Android,Android Emulator,Emulation,Android Location,我正在使用geocoder,它在我的设备上运行得很好,但在模拟器上不起作用。在2.2和4.2.2上尝试过它,但都不起作用 这是我的代码: Geocoder myLocation = new Geocoder(AzanTime.this, Locale.getDefault()); List<Address> myList=null; try { myList = myLocation.getFromLocation(latitude,longitude, 1); } catc

我正在使用geocoder,它在我的设备上运行得很好,但在模拟器上不起作用。在2.2和4.2.2上尝试过它,但都不起作用

这是我的代码:

Geocoder myLocation = new Geocoder(AzanTime.this, Locale.getDefault());
List<Address> myList=null;
try {
    myList = myLocation.getFromLocation(latitude,longitude, 1);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Address address = (Address) myList.get(0);
String addressStr = "";
if(address.getAddressLine(0)!=null){
    addressStr += address.getAddressLine(0);

}

模拟器上没有安装地理编码器。 参照

Geocoder类需要一个后端服务,该服务不包含在核心android框架中。如果平台中没有后端服务,Geocoder查询方法将返回空列表。使用isPresent()方法确定是否存在地理编码器实现

你应该检查一下

Geocoder.isPresent()
在访问API之前。 使用自己的实现更可靠。 检查我的实现的这个答案。

在某些版本上不起作用。我的记忆有点模糊,但我认为2.1还可以
Geocoder.isPresent()