请问地理codeR模拟器上工作 [英] Does the geocoder work on emulators
问题描述
我现在用的是地缘codeR,它的工作我的设备上得很好,但不工作的模拟器试图在2.2和4.2.2没有工作;
这是我的code:
地理codeR myLocation =新的地缘codeR(AzanTime.this,Locale.getDefault());
清单<地址> myList中= NULL;
尝试{
myList中= myLocation.getFromLocation(纬度,经度,1);
}赶上(IOException异常五){
// TODO自动生成catch块
e.printStackTrace();
}
地址地址=(地址)myList.get(0);
串addressStr =;
如果(address.getAddressLine(0)!= NULL){
addressStr + = address.getAddressLine(0); }
而logcat的:
九月一日至11日:31:07.573:E / AndroidRuntime(788):致命异常:主要
九月一日至11日:31:07.573:E / AndroidRuntime(788):了java.lang.RuntimeException:无法启动活动ComponentInfo{amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation/amina.myhomebusiness.IslamicApps.FortressOfTheMuslimExplanation.AzanTime}: java.lang.IllegalArgumentException异常:供应商不exisit:空
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.os.Handler.dispatchMessage(Handler.java:99)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.os.Looper.loop(Looper.java:137)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread.main(ActivityThread.java:5041)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在java.lang.reflect.Method.invokeNative(本机方法)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在java.lang.reflect.Method.invoke(Method.java:511)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在dalvik.system.NativeStart.main(本机方法)
九月一日至11日:31:07.573:E / AndroidRuntime(788):java.lang.IllegalArgumentException异常:产生的原因提供者不exisit:空
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.os.Parcel.readException(Parcel.java:1429)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.os.Parcel.readException(Parcel.java:1379)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.location.ILocationManager $存根$ Proxy.requestLocationUpdates(ILocationManager.java:538)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.location.LocationManager.requestLocationUpdates(LocationManager.java:836)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.location.LocationManager.requestLocationUpdates(LocationManager.java:430)九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.Activity.performCreate(Activity.java:5104)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
九月一日至11日:31:07.573:E / AndroidRuntime(788):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
九月一日至11日:31:07.573:E / AndroidRuntime(788):11 ...更多
有安装在仿真器没有地理$ C $铬。
Accroding到地理codeR 参考
中的地缘codeR类需要未包含在核心Android框架后端服务。地缘codeR查询方法将返回在平台列表为空,如果有没有后端服务。使用is present()方法来确定一个地理codeR实施是否存在。
块引用>您应该检查
地理coder.is present()
访问API之前。
它更可靠的使用自己的实现。
检查这个答案对我实施。
<一href=\"http://stackoverflow.com/questions/13906380/problems-with-android-location-geo$c$cr/15117087#15117087\">problems与android.location.geo codeRI 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
解决方案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
这篇关于请问地理codeR模拟器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!