Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:46+00:00 2026-06-17T17:30:46+00:00

I grab a code from the android site that do the reverse geocoding (transfering

  • 0

I grab a code from the android site that do the reverse geocoding (transfering a location from numbers to a text)

It’s working fine but since my application has changed a bit I need to change this code into a normal method, right now it’s an AsyncTask. It should get a Location and return a string.

This code is a bit strange to me so I need your help guys:

private class ReverseGeocodingTask extends AsyncTask<Location, Void, Void> 
{
    Context mContext;

    public ReverseGeocodingTask(Context context) 
    {
        super();
        mContext = context;
    }

    @Override
    protected Void doInBackground(Location... params) 
    {
        Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());

        Location loc = params[0];
        List<Address> addresses = null;
        try {
            addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
        } catch (IOException e) {
            e.printStackTrace();
            // Update address field with the exception.
            LocationService.this.address = e.toString();
        }
        if (addresses != null && addresses.size() > 0) 
        {
            Address address = addresses.get(0);
            // Format the first line of address (if available), city, and country name.
            String addressText = String.format("%s, %s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getLocality(),
                    address.getCountryName());
            // Update address field on UI.
           // Message.obtain(mHandler, UPDATE_ADDRESS, addressText).sendToTarget();
            LocationService.this.address = addressText;
        }
        return null;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:30:47+00:00Added an answer on June 17, 2026 at 5:30 pm

    You start by making a method like so

    public String reverseGeocode(Location loc) {
    
    
    }
    

    change the line that grabs the first location, being the only one used, and remove it – you already have loc

    //Location loc = params[0];
    

    Then instead of setting the address to that location service, just return it:

    //LocationService.this.address = addressText;
    return addressText;
    

    Splice those into the method, remove the unnecessary return statement at the end, and you’re golden.

    Upon a closer look I’m also seeing an exception you’ll simply want to throw up the chain instead of handling inside this method. Let that get handled by whatever calls your method on a case-by-case basis: it’s not a problem this method can solve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to save images from a specific URL using Image::Grab .
I am currently using this code to grab key-strokes, but I am missing e.g.
I'm looking for a simple line or two of code that will grab an
I'm working on a project for fun but i want to grab just the
I am making an Android application that can fetch the new announcements from the
I have been asked to grab a certain line from a page but it
I am porting iOS code that works perfectly to the Android OS. I perform
Im trying to grab a HTML source code from a webpage which needs user
I’m trying to read the HTTP response code from a remote server but am
I'm trying to grab frames from an Video file in android, the only alternative

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.