我编写了一个简单的 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/