osmdroid奖金包反向地理定位

时间:2014-10-06 14:02:40

标签: geolocation osmdroid

我试图找到一些关于使用osmdroid进行反向地理定位的示例,但却无法找到。 osmdroid奖金包也会发生同样的事情。 有人可以帮帮我吗?

这是logcat信息:

10-07 12:11:48.340: W/dalvikvm(5543): VFY:  rejected Lorg/osmdroid/bonuspack/location/GeocoderNominatim;.getFromLocation (DDI)Ljava/util/List;
10-07 12:11:48.340: W/dalvikvm(5543): VFY:  rejecting opcode 0x0d at 0x007a
10-07 12:11:48.340: W/dalvikvm(5543): VFY:  rejected Lorg/osmdroid/bonuspack/location/GeocoderNominatim;.getFromLocation (DDI)Ljava/util/List;
10-07 12:11:48.340: W/dalvikvm(5543): Verifier rejected class Lorg/osmdroid/bonuspack/location/GeocoderNominatim;
10-07 12:11:48.340: D/AndroidRuntime(5543): Shutting down VM
10-07 12:11:48.340: W/dalvikvm(5543): threadid=1: thread exiting with uncaught exception (group=0x40c2a1f8)
10-07 12:11:48.340: E/AndroidRuntime(5543): FATAL EXCEPTION: main
10-07 12:11:48.340: E/AndroidRuntime(5543): java.lang.VerifyError: org/osmdroid/bonuspack/location/GeocoderNominatim
10-07 12:11:48.340: E/AndroidRuntime(5543):     at com.aiscad.bustiaciutadana.MapActivity.getMyLocationAddress(MapActivity.java:242)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at com.aiscad.bustiaciutadana.MapActivity.dispatchTouchEvent(MapActivity.java:135)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at  android.view.View.dispatchPointerEvent(View.java:5890)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3136)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2678)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:1036)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2687)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.os.Looper.loop(Looper.java:137)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at android.app.ActivityThread.main(ActivityThread.java:4507)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at java.lang.reflect.Method.invokeNative(Native Method)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at java.lang.reflect.Method.invoke(Method.java:511)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
10-07 12:11:48.340: E/AndroidRuntime(5543):     at dalvik.system.NativeStart.main(Native Method)

以下是代码:

String theAddress;
    try {
            GeocoderNominatim geocoder = new GeocoderNominatim(getBaseContext());
            double dLatitude = latitude;
            double dLongitude = longitude;
            List<Address> addresses = geocoder.getFromLocation(dLatitude, dLongitude, 1);
            StringBuilder sb = new StringBuilder(); 
            if (addresses.size() > 0) {
                    Address address = addresses.get(0);
                    int n = address.getMaxAddressLineIndex();
                    for (int i=0; i<=n; i++) {
                            if (i!=0)
                                    sb.append(", ");
                            sb.append(address.getAddressLine(i));
                    }
                    theAddress = new String(sb.toString());
                    direccion = theAddress;
                    Log.d(TAG, "direccion: " + theAddress);
            } else {
                    theAddress = null;
                    direccion = null;
            }
    } catch (Exception e) {
            theAddress = null;
            e.printStackTrace();
    }

2 个答案:

答案 0 :(得分:1)

使用OSMBonusPack时,您可以使用GeocoderNominatim进行反向地理编码,就像使用标准Android Geocoder一样。

您可以在OSMNavigator MapActivity中看到它的真实用法。

答案 1 :(得分:0)

好的我终于使用Geocoder类而不是GeocoderNominatim类了。 它与使用GeocoderNominatim的代码相同,但用Geocoder替换它。