【问题标题】:Does the geocoder work on emulators地理编码器是否适用于模拟器
【发布时间】:2014-01-30 10:06:40
【问题描述】:

我正在使用地理编码器,它在我的设备上运行良好,但不能在模拟器上运行,在 2.2 和 4.2.2 上尝试了它没有工作;

这是我的代码:

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);

}

还有日志猫:

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

【问题讨论】:

  • 不适用于某些版本。我对此的记忆有点模糊,但我认为2.1还可以

标签: android android-emulator emulation android-location


【解决方案1】:

模拟器上没有安装地理编码器。 根据Geocoder参考

Geocoder 类需要一个不包含在核心 android 框架中的后端服务。如果平台中没有后端服务,Geocoder 查询方法将返回一个空列表。使用 isPresent() 方法确定是否存在 Geocoder 实现。

你应该检查一下

Geocoder.isPresent()

在访问 API 之前。 使用自己的实现更可靠。 检查这个答案以了解我的实施。 problems with android.location.geocoder

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多