Android地理编码器isPresent返回false,后端服务丢失了吗?

时间:2016-01-18 16:22:47

标签: android google-geocoder

我实施了一个使用反向地理编码服务的小应用,但它在使用Android 4.4.2(root)的特定设备上无法正常工作。 使用geocoder.getFromLocation()始终返回0结果。调用geocoder.isPresent()始终返回false。

我使用Android 4.4.4和4.1.2在其他设备上运行相同的代码,它运行顺畅。

有问题的设备缺少我手动安装的几个Google软件包(Google Play服务,地图等)。

我已经看过几个类似的问题,但还没有找到答案。

有人可以告诉我怎样才能找到手机上缺少的支持服务? 或其他一些解决方案? (不是谷歌地图API)

以下是我用于反向地理编码的代码:

public void getMyLocationAddress() {
        double fixLatitude = 37.423247;
        double fixLongitude = -122.085469;
        Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);

        if (geocoder.isPresent()) {
            Toast.makeText(getApplicationContext(),"geocoder.isPresent..!", Toast.LENGTH_LONG).show();
            try {
                List<Address> addresses = geocoder.getFromLocation(fixLatitude, fixLongitude, 1);
                if(addresses != null) {
                    Address fetchedAddress = addresses.get(0);
                    StringBuilder strAddress = new StringBuilder();
                    for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) {
                        strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
                    }
                    tvLocationAddress.setText("I am at: " +strAddress.toString());
                }
                else
                    tvLocationAddress.setText("No location found..!");
            }
            catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(),"Could not get address..!", Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "NOTTTTT geocoder.isPresent..! ", Toast.LENGTH_SHORT).show();
        }
    }

以下是build.gradle的一部分:

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
    minSdkVersion 16
    targetSdkVersion 22
}
dependencies {
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.google.android.gms:play-services-location:8.1.0'
    compile 'com.google.android.gms:play-services-maps:8.1.0'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}

谢谢。

0 个答案:

没有答案