0

I'm trying to find some example about reverse geolocation with osmdroid but can't find any. The same thing happens with osmdroid bonus pack. Can somebody help me please?

Here is the logcat info:

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)

And here is the code:

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();
    }
cristina
  • 21
  • 7

2 Answers2

1

When using OSMBonusPack, you can use GeocoderNominatim for reverse geocoding, as you would use the standard Android Geocoder.

You can see it's real life usage in OSMNavigator MapActivity.

MKer
  • 3,430
  • 1
  • 13
  • 18
  • I'm trying to implement it but can't make it work yet. With Geocoderit works (but the address is not correct for the coodinates passed for some streets of difference), but when I try to change Geocoder for GeocoderNominatim the app crushes. – cristina Oct 07 '14 at 08:43
  • I try to run the example https://code.google.com/p/osmbonuspack/source/browse/trunk/OSMBonusPackDemo/src/com/osmbonuspackdemo/MapActivity.java?r=48 – cristina Oct 07 '14 at 09:57
  • but always crushes too in the same line -> GeocoderNominatim geocoder = new GeocoderNominatim(this); – cristina Oct 07 '14 at 09:58
  • Look at the stack trace. And provide it if reason is not clear and you need help. – MKer Oct 07 '14 at 10:04
  • I have added the logcat answer and the piece of code that doesn't work. – cristina Oct 07 '14 at 10:22
  • See http://stackoverflow.com/questions/100107/reasons-of-getting-a-java-lang-verifyerror – MKer Oct 07 '14 at 13:09
0

OK I'm finally using Geocoder class instead of the GeocoderNominatim class. It's the same pice of code than with GeocoderNominatim but replacing it with Geocoder.

cristina
  • 21
  • 7
  • I got a problem because it seemed to give me the wrong address back but I realized it was giving me the address where I had a button to go back to another activity... so I created a list of OverlayItems and just took the address of the penultimate item. – cristina Oct 07 '14 at 11:57
  • Up to you. But notice that it's not allowed by Google Terms&Conditions. (https://developers.google.com/maps/terms, item (g): No Use of Content without a Google Map) – MKer Oct 07 '14 at 13:09
  • I don't understand MKer... I'm using OSMdroid for maps and Geocoder class from android API. Nothing related to Google... – cristina Oct 07 '14 at 14:39
  • ok then I will left this project for some time, I am like stuck. I was just having fun, nothing serious. Will take a look at GeocoderNominatim implementation again. Thanks. – cristina Oct 08 '14 at 09:20