android – Geocoder的isPresent()方法总是返回false
作者:互联网
我写了一个简单的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()总是假装错误?
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,google-geocoder 来源: https://codeday.me/bug/20190613/1234424.html