2

I have following code to get full address string after providing lat and lng. But it is giving an exception all the time. I don't know why this code is not returning address. Please help. Thanks.

private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
        String strAdd = "";
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
            if (addresses != null) {
                Address returnedAddress = addresses.get(0);
                StringBuilder strReturnedAddress = new StringBuilder("");

                for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                    strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
                }
                strAdd = strReturnedAddress.toString();
                Log.w("My Current loction address", "" + strReturnedAddress.toString());
            } else {
                Log.w("My Current loction address", "No Address returned!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.w("My Current loction address", "Canont get Address!");
        }
        return strAdd;
    }

LogCat

04-05 09:28:44.217: I/SurfaceTextureClient(4578): [STC::queueBuffer] this:0x55815618, api:1, last queue time elapsed :225623 ms
04-05 09:28:44.218: I/SurfaceTextureClient(4578): [0x55815618] frames:2, duration:225.699997, fps:0.008861
04-05 09:28:44.265: V/Provider/Setting(4578): from settings cache , name = sound_effects_enabled value = 0
04-05 09:28:44.290: W/System.err(4578): java.io.IOException: Service not Available
04-05 09:28:44.342: W/System.err(4578):     at android.location.Geocoder.getFromLocation(Geocoder.java:139)
04-05 09:28:44.342: W/System.err(4578):     at com.beproject.ourway.Panic.getCompleteAddressString(Panic.java:70)
04-05 09:28:44.343: W/System.err(4578):     at com.beproject.ourway.Panic.getLocation(Panic.java:102)
04-05 09:28:44.343: W/System.err(4578):     at com.beproject.ourway.Panic.onOptionsItemSelected(Panic.java:158)
04-05 09:28:44.343: W/System.err(4578):     at android.app.Activity.onMenuItemSelected(Activity.java:2546)
04-05 09:28:44.343: W/System.err(4578):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:971)
04-05 09:28:44.343: W/System.err(4578):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
04-05 09:28:44.344: W/System.err(4578):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
04-05 09:28:44.344: W/System.err(4578):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
04-05 09:28:44.344: W/System.err(4578):     at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:523)
04-05 09:28:44.344: W/System.err(4578):     at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:100)
04-05 09:28:44.344: W/System.err(4578):     at android.view.View.performClick(View.java:4091)
04-05 09:28:44.345: W/System.err(4578):     at android.view.View$PerformClick.run(View.java:17072)
04-05 09:28:44.345: W/System.err(4578):     at android.os.Handler.handleCallback(Handler.java:615)
04-05 09:28:44.345: W/System.err(4578):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-05 09:28:44.346: W/System.err(4578):     at android.os.Looper.loop(Looper.java:153)
04-05 09:28:44.346: W/System.err(4578):     at android.app.ActivityThread.main(ActivityThread.java:4987)
04-05 09:28:44.346: W/System.err(4578):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 09:28:44.346: W/System.err(4578):     at java.lang.reflect.Method.invoke(Method.java:511)
04-05 09:28:44.346: W/System.err(4578):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
04-05 09:28:44.346: W/System.err(4578):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
04-05 09:28:44.347: W/System.err(4578):     at dalvik.system.NativeStart.main(Native Method)
04-05 09:28:44.347: W/My Current loction address(4578): Canont get Address!
3
  • what is the stacktrace and e.getMessage()? Commented Apr 5, 2015 at 3:58
  • This may help: stackoverflow.com/questions/4761052/… Commented Apr 5, 2015 at 4:01
  • I am not getting that answer :( Commented Apr 5, 2015 at 4:02

1 Answer 1

1

The Geocoder is pretty flaky. When it gets into the state you are reporting, rebooting the device usually "fixes" it. If you want a reliable solution I would recommend checking out the Google Geocoding API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.