0

所以我在我的应用程序中为地图编写了一些代码,它在我的手机上运行得很好,遗憾的是它在我的模拟器上不起作用,这对我来说不够舒服这里是代码:

String  searchString = mSearchText.getText().toString();

Geocoder geocoder = new Geocoder(this);
List<Address> list = new ArrayList<>();
try{
    int i=0;
    while(list.size()==0 && i<10) {
        boolean a = geocoder.isPresent();
        list = geocoder.getFromLocationName(searchString,1);
        i++;
    }
}catch(IOException e){
    Log.d(TAG, "geoLocate: IOException " + e.getMessage());
}

所以当我调试它时,我看到变量“a”在我的模拟器上总是假的。

我将 android 模拟器用于 Visual Studio,因为我有一个 AMD 处理器(Ryzen 7 1800x),我在上面安装了 google play 商店和 google play 服务(地图工作得很好,只是地理编码器不行),现在有什么方法可以解决它?

正如我在https://developer.android.com/reference/android/location/Geocoder.html网站上所读到的, “如果平台中没有后端服务,Geocoder 查询方法将返回一个空列表。” 我能以某种方式获得服务吗?在我的模拟器或类似的东西上下载它?

4

1 回答 1

0

首先, isPresent() 是一个静态方法,所以调用应该是

Geocoder.isPresent();

IsPresent 方法“如果实施了地理编码器方法 getFromLocation 和 getFromLocationName,则返回 true”,否则返回 false。一些模拟器没有安装地理编码器服务。是方法

geocoder.getFromLocationName 

返回您需要的内容或空数组?

您的代码片段在我的 Nexus 6P Android 7.0 API 24 模拟器上运行良好。

于 2018-04-24T08:52:27.240 回答