Does the geocoder work on emulators

百般思念 提交于 2019-12-20 02:36:13

问题


I am using the geocoder and it worked just fine on my device but not working on emulators tried it on 2.2 and 4.2.2 didn't work;

this is my code:

Geocoder myLocation = new Geocoder(AzanTime.this, Locale.getDefault());
List<Address> myList=null;
try {
    myList = myLocation.getFromLocation(latitude,longitude, 1);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Address address = (Address) myList.get(0);
String addressStr = "";
if(address.getAddressLine(0)!=null){
    addressStr += address.getAddressLine(0);

}

And the logcat:

01-11 09:31:07.573: E/AndroidRuntime(788): FATAL EXCEPTION: main
01-11 09:31:07.573: E/AndroidRuntime(788): java.lang.RuntimeException: Unable to start activity ComponentInfo{amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation/amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation.AzanTime}: java.lang.IllegalArgumentException: provider doesn't exisit: null
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.os.Looper.loop(Looper.java:137)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread.main(ActivityThread.java:5041)
01-11 09:31:07.573: E/AndroidRuntime(788):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 09:31:07.573: E/AndroidRuntime(788):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 09:31:07.573: E/AndroidRuntime(788):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-11 09:31:07.573: E/AndroidRuntime(788):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-11 09:31:07.573: E/AndroidRuntime(788):  at dalvik.system.NativeStart.main(Native Method)
01-11 09:31:07.573: E/AndroidRuntime(788): Caused by: java.lang.IllegalArgumentException: provider doesn't exisit: null
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.os.Parcel.readException(Parcel.java:1429)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.os.Parcel.readException(Parcel.java:1379)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:538)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:836)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:430)

01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.Activity.performCreate(Activity.java:5104)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-11 09:31:07.573: E/AndroidRuntime(788):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-11 09:31:07.573: E/AndroidRuntime(788):  ... 11 more

回答1:


There is no Geocoder installed on emulators. Accroding to Geocoder reference

The Geocoder class requires a backend service that is not included in the core android framework. 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.

You should have checked

Geocoder.isPresent()

Before accessing the API. It's more reliable to use your own implementation. Check this answer for my implementation. problems with android.location.geocoder



来源:https://stackoverflow.com/questions/21061175/does-the-geocoder-work-on-emulators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!