android - Geocoder 的 isPresent() 方法总是返回 false

标签 android google-geocoder

我编写了一个简单的 Activity 来测试 Geocoder 的存在,调用 Geocoder.isPresent() 总是返回 false。

类:

public class LocationTestActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LocationManager locationManager = (LocationManager)  this.getSystemService(Context.LOCATION_SERVICE);
        Log.d( "LocationTestActivity", "Geocoder.isPresent : " + Geocoder.isPresent() );

    }
}


AndroidManifest.xml 在“application”元素之前还有以下条目:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


环境:Eclipse Indigo 3.7.1,XP Professional 2002 SP 3 上的 ICS 4.0 模拟器

请帮助我理解:
1. 为什么 Geocoder.isPresent() 总是返回 false?
2. 要进行哪些更改才能使 Geocoder.isPresent() 返回 true?

提前致谢!

最佳答案

实际上是Geocoder需要框架在后台运行的服务。

来自文档:

The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

所以如果我们查看 isPresent() 的文档,它说。

Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented. Lack of network connectivity may still cause these methods to return null or empty lists.

注意:请记住,isPresent() 在 Pre-Api 9 平台中不可用。

关于android - Geocoder 的 isPresent() 方法总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9075446/

相关文章:

Android:如何在 Activity 之上获得覆盖

android - 在 Android manifest 中,如何要求两个硬件中的至少一个?

android - 设备显示为 'adb devices' 但不在 visual studio (xamarin.android) 上

javascript - React Geocode 包返回 React 中已实现的 Promise 对象

jquery - 谷歌地图地理编码器 : Return postal_code

javascript - Google map 地理编码邮政编码 0821 仅适用于澳大利亚

android - 将 EditText 调整为字体大小

java - Android 相机示例 NullPointerException

android - 有什么方法可以获取 Google Place picker android 的城市名称

java.io.IOException : grpc failed